QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100

#10424. 已知与未知

Estadísticas

两位数学教授在同一天有办公时间。学生们逐一拜访每位教授以提交作业解答。在整个学期中,两位教授都设定了固定的学生拜访顺序。共有 $n$ 名学生,用从 $1$ 到 $n$ 的整数表示。每位教授的学生顺序都是 $1$ 到 $n$ 的一个排列。

今天只有部分学生来到了学校;设 $A$ 为今天在校的学生编号集合。集合 $A$ 中的所有学生都拜访了两位教授,而集合 $A$ 之外的所有学生都没有拜访任何一位教授。

每位教授都制作了一份他们交谈过的学生名单,名单顺序与学生拜访的顺序相同。注意,该名单必须符合教授设定的顺序,唯一的区别是集合 $A$ 之外的学生在名单中缺失。由于学期刚开始,教授们还没机会认识每一位学生。因此,对于教授认识的学生,名单中包含他们的编号;而对于教授不认识的学生,名单中包含 $-1$。

考虑一个例子:第一位教授的顺序是 $[1, 2, 3, 4]$,第二位教授的顺序是 $[3, 2, 4, 1]$。今天第一位教授制作的名单是 $[1, -1, -1]$,第二位教授制作的名单是 $[3, -1, 1]$。根据这些名单,我们可以立即看出今天有三名学生拜访了学校。我们可以推断集合 $A$ 要么是 $\{1, 2, 3\}$,要么是 $\{1, 3, 4\}$。

给定两个排列——即每位教授设定的顺序;同时给定两位教授今天制作的两份名单。你的任务是帮助教授们。根据提供的数据,确定每位学生是确定拜访了学校、确定没有拜访,还是无法确定。注意,教授们可能会弄混学生,因此给定的数据可能存在矛盾。

输入格式

第一行包含一个整数 $T$ ($T \ge 1$),表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 2000$),表示学生人数。

第二行包含 $n$ 个不同的整数 $p_{1,1}, p_{1,2}, \dots, p_{1,n}$,表示第一位教授设定的顺序,即学生 $p_{1,1}$ 最先,学生 $p_{1,n}$ 最后 ($1 \le p_{1,i} \le n$)。

第三行包含 $n$ 个不同的整数 $p_{2,1}, p_{2,2}, \dots, p_{2,n}$,表示第二位教授设定的顺序,格式相同 ($1 \le p_{2,i} \le n$)。

第四行包含一个整数 $k$,表示今天拜访学校的学生人数 ($1 \le k \le n$)。

第五行包含 $k$ 个整数 $s_{1,1}, s_{1,2}, \dots, s_{1,k}$,表示第一位教授的名单。每位学生在名单中最多出现一次 ($s_{1,i} = -1$ 或 $1 \le s_{1,i} \le n$)。

第六行包含 $k$ 个整数 $s_{2,1}, s_{2,2}, \dots, s_{2,k}$,表示第二位教授的名单,格式相同 ($s_{2,i} = -1$ 或 $1 \le s_{2,i} \le n$)。

所有测试用例中 $n$ 的总和不超过 $2000$。

输出格式

对于每个测试用例,输出一个字符串。如果给定数据存在矛盾,输出单词 “Inconsistent”。否则,输出一个长度为 $n$ 的字符串,其中第 $i$ 个字符表示第 $i$ 号学生的情况:若该学生今天拜访了学校,则为 ‘Y’;若该学生今天没有拜访学校,则为 ‘N’;若无法确定,则为 ‘?’。

样例

输入 1

2
4
1 2 3 4
3 2 4 1
3
1 -1 -1
3 -1 1
4
1 2 3 4
3 2 4 1
3
1 -1 2
3 -1 1

输出 1

Y?Y?
Inconsistent

输入 2

2
3
1 2 3
2 1 3
2
-1 2
-1 -1
3
1 2 3
3 2 1
2
1 3
2 -1

输出 2

YYN
Inconsistent

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.