QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 512 MB 満点: 100

#3677. 键盘共识

統計

著名的年轻程序员 Kolya 和 Kostya 正在为即将到来的团队竞赛做准备。他们需要做出的重要决定之一是选择一个他们都觉得舒适的键盘。为了达成共识,他们决定采用以下程序:

共有 $n$ 个键盘,编号从 $1$ 到 $n$。最初,候选集合包含所有 $n$ 个键盘。程序员轮流操作,Kolya 先手。在每一轮中,程序员从集合中移除一个键盘。集合中最后剩下的一个键盘将被选为竞赛使用的键盘。

每位程序员都准备了一个包含所有 $n$ 个键盘的列表,按他们从最喜欢到最不喜欢的顺序排列。Kolya 和 Kostya 都希望最小化所选键盘在各自列表中的位置。他们都知道对方的列表。

请找出如果两位程序员都采取最优策略时最终会被选中的键盘,以及 Kolya 的所有最优首步操作——即他可以在第一轮移除哪些键盘以确保自己获得尽可能好的结果。

输入格式

第一行包含一个整数 $n$ —— 键盘的数量 ($2 \le n \le 100$)。第二行包含 $n$ 个 $1$ 到 $n$ 之间的不同整数 —— Kolya 列表中的键盘编号,按他从最喜欢到最不喜欢的顺序排列。第三行以相同格式包含 Kostya 的列表。

输出格式

第一行输出一个整数 —— 被选中的键盘编号。第二行输出 Kolya 的最优首步操作数量。第三行按升序输出这些操作。

样例

样例输入 1

5
1 2 3 4 5
5 4 3 2 1

样例输出 1

3
2
4 5

样例输入 2

4
1 2 3 4
1 3 2 4

样例输出 2

1
3
2 3 4

样例输入 3

3
3 1 2
1 3 2

样例输出 3

3
1
1

样例输入 4

4
4 1 3 2
1 3 4 2

样例输出 4

1
3
2 3 4

说明

在第一个样例中,Kolya 将以任意顺序移除键盘 4 和 5,Kostya 将以任意顺序移除键盘 1 和 2。因此,键盘 3 将被选中。

在第二个样例中,他们都喜欢键盘 1,因此他们会以任意顺序移除所有其他键盘。

在第三个样例中,Kolya 唯一的最优操作是在他的回合移除键盘 1。Kostya 将在键盘 2 和 3 之间做出选择,由于键盘 3 对他来说更好,他会移除键盘 2。

在第四个样例中,通过对所有可能操作的简单搜索表明,Kolya 无法强制选中键盘 4,答案是 1。

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.