QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 1024 MB 満点: 100

#7551. 寻找数字

統計

David 和 Harry 是国际扑克牌学院的朋友。有一天,David 遇见了 Harry 并说道:

“我要为你表演一个魔术。在 1 到 12 之间选一个数字。但不要告诉我!把它记在心里就行。”

Harry 暗中选择了 11。接着,David 一张接一张地向 Harry 展示了以下四张卡片。在展示每张卡片时,他都问:“你的数字在这张卡片上吗?”

于是,Harry 依次回答了“Yes, yes, no, yes”。在那之后,David 用手臂和腿做了一些看起来很神奇的动作,然后大喊道:“我已经猜到你的数字了。是 11。”Harry 非常惊讶,因为这正是他选择的数字,而且他一直保密着。

David 没有告诉 Harry 这个魔术的秘密。他只是说:“这些卡片拥有强大的魔力,所以它们可以读懂你的心思,并用一种只有我能听懂的魔法语言告诉我答案。”

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

现在,你需要编写一个程序来猜出朋友们心中的数字。我们可以将这个魔术推广如下:你有 $K$ 张魔法卡片。每张卡片上恰好写有 $M$ 个整数。所有整数都在 $1$ 到 $N$ 之间。你对 $F$ 个朋友表演这个魔术。他们每个人都会如实回答你的问题。对于每个朋友,根据他们的回答,猜出他们心中想的数字,或者确定这是不可能的。

输入格式

输入的第一行包含四个整数 $N, K, M$ 和 $F$ ($1 \le N \le 500\,000, 1 \le K \le 100, 1 \le M \le 5000, 1 \le F \le 50\,000$)。

接下来的 $K$ 行,每行包含 $M$ 个 $1$ 到 $N$ 之间的整数:即写在相应魔法卡片上的数字。

接下来的 $F$ 行,每行给出一个长度为 $K$ 的字符串,代表相应朋友的回答。每个字符要么是 ‘Y’(表示“yes”),要么是 ‘N’(表示“no”)。你可以假设每个朋友心中都想了一个 $1$ 到 $N$ 之间的整数,且每个人都如实回答了你的问题。

输出格式

输出共 $F$ 行。对于每个 $i = 1, 2, \dots, F$,第 $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.