QOJ.ac

QOJ

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

#7949. K-Lottery

الإحصائيات

K-Lottery 每轮只产生一名获胜者。每一轮会生成 $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$)。假设预定生成的 10 个随机数为 $(20, 35, 10, 7, 99, 53, 72, 33, 88, 16)$ ($N = 10$)。那么 $(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$)。假设预定生成的 10 个随机数为 $(19, 31, 9, 1, 89, 48, 63, 30, 78, 12)$ ($N = 10$)。那么 $(89, 48, 63, 30)$ 的相对顺序为 $(4, 2, 3, 1)$,这与已售出的彩票 $(4, 2, 3, 1)$ 匹配,因此该彩票获胜。

给定 $K$-Lottery 一轮的相关信息,包括生成的彩票数量、已售出彩票的数字序列以及用于确定获胜者的预定随机生成序列,编写一个程序输出获胜彩票的数字序列。

输入格式

程序从标准输入读取数据。输入的第一行包含三个整数 $K, M$ 和 $N$ ($3 \le K \le 10,000$, $1 \le M \le \min(K!, 1,000)$, $K \le N \le 1,000,000$, $3 \le N \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.