QOJ.ac

QOJ

時間限制: 5.0 s 記憶體限制: 1024 MB 總分: 100

#7556. 运气之王

统计

“King of Luck” 彩票每轮最多产生一名获胜者。每轮会产生 $K!$ 张彩票:每张彩票包含 $1$ 到 $K$ 之间 $K$ 个不同的数字,且没有两张彩票是完全相同的。在每轮产生的彩票中,有 $M$ 张彩票被售出。每轮开奖过程如下:总共随机生成 $N$ 个不同的数字($N \ge K$),一个接一个地生成。如果在生成某个数字后,最后生成的 $K$ 个连续数字的相对顺序与任何一张已售出彩票上的数字顺序相匹配,则开奖立即结束,对应的彩票获胜。注意,由于开奖只考虑已售出的彩票,因此某些轮次可能没有获胜彩票。

例如,考虑一轮产生 6 张彩票的情况($K = 3$)。彩票上的序列为 $(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2)$ 和 $(3, 2, 1)$。假设其中 $(1, 2, 3)$ 和 $(1, 3, 2)$ 被售出($M = 2$)。假设计划生成的 $N = 10$ 个不同的随机数字为:$(20, 35, 10, 7, 99, 53, 72, 33, 88, 16)$。那么 $(7, 99, 53)$ 的相对顺序为 $(1, 3, 2)$,这与已售出的彩票 $(1, 3, 2)$ 相匹配,因此该彩票赢得本轮比赛。

在另一种情况下,考虑一轮产生 24 张彩票的情况($K = 4$)。产生的彩票序列为 $(1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), \dots$ 以及 $(4, 3, 2, 1)$。假设其中 $(1, 2, 3, 4), (1, 2, 4, 3), (3, 4, 1, 2), (4, 1, 2, 3)$ 和 $(4, 2, 3, 1)$ 被售出($M = 5$)。假设计划生成的 $N = 10$ 个不同的随机数字为:$(19, 31, 9, 1, 89, 48, 63, 30, 78, 12)$。那么 $(89, 48, 63, 30)$ 的相对顺序为 $(4, 2, 3, 1)$,这与已售出的彩票 $(4, 2, 3, 1)$ 相匹配,因此该彩票赢得本轮比赛。

给定有关彩票轮次的信息,包括产生的彩票数量、已售出彩票的数字序列以及计划随机生成的获胜数字序列,编写一个程序来找出获胜彩票的数字序列。

输入格式

输入的第一行包含三个整数 $K, M$ 和 $N$($3 \le K \le 10\,000, 1 \le M \le \min(K!, 1000), K \le N \le 1\,000\,000, 3 \le K \cdot M \le 100\,000$),其中 $K$ 是每张彩票上的数字个数,$M$ 是售出的彩票数量,$N$ 是本轮随机生成序列的长度。接下来的 $M$ 行,每行包含 $K$ 个整数,描述一张已售出的彩票。最后一行包含 $N$ 个不同的正整数 $N_i$($1 \le N_i \le 100\,000\,000, 1 \le i \le N$),即用于确定获胜者的数字序列。

输出格式

输出仅一行。该行应包含获胜彩票的数字序列。如果没有获胜彩票,则输出 0。

样例

样例输入 1

3 2 10
1 2 3
1 3 2
20 35 10 7 99 53 72 33 88 16

样例输出 1

1 3 2

样例输入 2

4 5 10
1 2 3 4
1 2 4 3
3 4 1 2
4 1 2 3
4 2 3 1
19 31 9 1 89 48 63 30 78 12

样例输出 2

4 2 3 1

样例输入 3

3 3 7
1 3 2
2 3 1
2 1 3
11 22 33 44 55 66 77

样例输出 3

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.