QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 2048 MB Total points: 100

#7951. Magic Cards

الإحصائيات

Chansu 和 Junsu 是国际编程融合学院的朋友。有一天,Chansu 见到 Junsu 并说:“我要为你表演一个魔术。在 1 到 12 之间选一个数字,不要告诉我。把它记在心里就行。”Junsu 心里选了 11。接着,Chansu 依次向 Junsu 展示了四张卡片,每次都问:“你的数字在这张卡片上吗?”

于是,Junsu 依次回答了“是、是、否、是”。在 Chansu 用手脚做了一些看起来很神奇的动作后,他大喊道:“我已经猜到你的数字了。是 11。”Junsu 非常惊讶,因为这正是他心里想的数字。

Chansu 没有告诉 Junsu 这个魔术的秘密,只是说:“这些卡片拥有强大的魔力,它们能读懂你的心思,并用一种只有我能听懂的魔法语言告诉我一些事情。”

这是如何运作的?你能找出其中的秘密吗?

现在,你需要编写一个程序来回答朋友们心中所想的数字。我们可以将这个魔术推广如下:你有 $K$ 张魔法卡片,每张卡片上恰好写有 $1$ 到 $N$ 之间的 $M$ 个整数(可能存在重复)。你对 $F$ 个朋友表演这个魔术。根据这 $F$ 个朋友给出的“是/否”序列,你将能够选出正确的数字。

输入格式

程序从标准输入读取数据。输入的第一行包含四个整数 $N$、$K$、$M$ 和 $F$ ($1 \le N \le 500,000$, $1 \le K \le 100$, $1 \le M \le 5,000$, $1 \le F \le 50,000$)。接下来的 $K$ 行,每行包含 $1$ 到 $N$ 之间的 $M$ 个整数,表示每张魔法卡片上写的 $M$ 个数字。接下来的 $F$ 行,每行给出一个长度为 $K$ 的字符串,由 {Y, N} 组成,表示每个朋友的回答,其中 Y 表示“是”,N 表示“否”。你可以假设所有朋友的回答都是根据他们心中所选的数字正确给出的。

输出格式

程序向标准输出写入数据。输出共 $F$ 行。对于每个 $i = 1, 2, \dots, F$,第 $i$ 行应包含第 $i$ 个朋友心中所想的数字。如果无法确定第 $i$ 个朋友心中唯一的数字,则在第 $i$ 行输出 0。

样例

输入 1

12 4 6 3
1 9 7 11 3 5
2 10 3 6 7 11
4 5 6 7 6 12
8 11 10 9 12 9
YYNY
NNNY
YNNN

输出 1

11
8
1

输入 2

13 4 6 4
1 9 7 11 3 5
2 10 3 6 7 11
4 5 6 7 6 12
8 11 10 9 12 9
YYNY
NNNY
YNNN
NNNN

输出 2

11
8
1
13

输入 3

14 4 6 4
1 9 7 11 3 5
2 10 3 6 7 11
4 5 6 7 6 12
8 11 10 9 12 9
YYNY
NNNY
YNNN
NNNN

输出 3

11
8
1
0

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.