CF1404D.Game of Pairs
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
Consider a fixed positive integer n. Two players, First and Second play a game as follows:
- First considers the 2n numbers 1,2,…,2n, and partitions them as he wants into n disjoint pairs.
- Then, Second chooses exactly one element from each of the pairs that First created (he chooses elements he wants).
To determine the winner of the game, we compute the sum of the numbers chosen by Second. If the sum of all these numbers is a multiple of 2n, then Second wins. Otherwise, First wins.
You are given the integer n. Your task is to decide which player you wish to play as and win the game.
Interaction
The interaction begins by reading the integer n (1≤n≤5⋅105).
After reading, print a single line containing either First or Second, denoting who you want to play as. The interaction then varies depending on who you chose to play as.
If you chose to play as First, print a single line containing 2n integers p1,p2,…,p2n, denoting that the number i belongs to the pi-th pair for 1≤i≤2n. Thus, 1≤pi≤n, and every number between 1 and n inclusive should appear exactly twice.
If you chose to play as Second, the interactor will print 2n integers p1,p2,…,p2n, denoting that the number i belongs to the pi-th pair. As a response, print n integers a1,a2,…,an in a single line. These should contain exactly one number from each pair.
Regardless of who you chose to play as the interactor will finish by printing a single integer: 0 if your answer for the test case is correct (that is, you are playing as First and it cannot choose adequate numbers from your pairs, or you are playing as Second and your chosen numbers add up to a multiple of 2n), or −1 if it is incorrect. In particular, the interactor will not print the chosen numbers if you choose to play First and lose. In either case, your program should terminate immediately after reading this number.
If at any point you make an invalid interaction, the interactor will print −1 and finish the interaction. You will receive a Wrong Answer verdict. Make sure to terminate immediately to avoid getting other verdicts.
After printing something do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hack Format
To hack, use the following format:
The first line contains an integer n (1≤n≤5⋅105).
The second line contains 2n integers p1,p2,…,p2n, denoting that the number i belongs to the pi-th pair if the solution being hacked chooses to play as Second. If the solution being hacked chooses to play as First, those pairs don't matter but the p1,p2,…,p2n must still form a valid partition of 1,2,…,2n into n disjoint pairs.
这是一个交互式问题。
考虑一个固定的正整数 n。两名玩家“先手”(First)和“后手”(Second)按如下规则进行一场游戏:
- 先手考虑 2n 个数 1,2,…,2n,并按其意愿将它们划分为 n 个互不相交的数对。
- 然后,后手从先手所创建的每个数对中恰好选择一个元素(可自由选择)。
为判定游戏胜者,我们计算后手所选数字之和。若该和是 2n 的倍数,则后手获胜;否则,先手获胜。
你将被给定整数 n。你的任务是决定希望扮演哪一方(先手或后手),并赢得这场游戏。
交互流程
交互开始时,首先读入整数 n(1≤n≤5⋅105)。
读入后,请输出一行,内容为 First 或 Second,表示你希望扮演的角色。随后的交互流程将取决于你所选择的角色。
-
若你选择扮演先手,请输出一行,包含 2n 个整数 p1,p2,…,p2n,表示:对每个 i(1≤i≤2n),数字 i 属于第 pi 个数对。因此,需满足 1≤pi≤n,且 1 到 n 中的每个整数恰好出现两次。
-
若你选择扮演后手,交互器将输出 2n 个整数 p1,p2,…,p2n,含义同上(即数字 i 属于第 pi 个数对)。作为回应,请在一行中输出 n 个整数 a1,a2,…,an,其中每个 aj 是第 j 个数对中被选出的一个数(即每个数对中恰好选一个数)。
无论你选择扮演哪一方,交互器最后都会输出一个整数:
- 若为
0,表示你对该测试用例的回答正确(即:你扮演先手,且后手无法从你构造的数对中选出和为 2n 倍数的 n 个数;或你扮演后手,且你选出的 n 个数之和是 2n 的倍数); - 若为
-1,表示你回答错误。特别地,若你选择扮演先手但失败了,交互器不会输出后手实际选择的数字。无论哪种情况,你的程序都必须在读入该整数后立即终止。
若在任意时刻你进行了非法交互(例如输出格式错误、数值越界等),交互器将输出 -1 并结束交互,你将收到“答案错误”(Wrong Answer)判据。请确保立即终止程序,以免获得其他判据。
每次输出后,请勿忘记输出换行符并刷新输出缓冲区。否则,你将收到“空闲超时”(Idleness limit exceeded)提示。为此,请使用以下方式之一:
- C++ 中:
fflush(stdout)或cout.flush(); - Java 中:
System.out.flush(); - Pascal 中:
flush(output); - Python 中:
stdout.flush(); - 其他语言请查阅相应文档。
Hack 格式
用于 Hack 的输入格式如下:
第一行为一个整数 n(1≤n≤5⋅105)。
第二行为 2n 个整数 p1,p2,…,p2n,其含义为:若被 Hack 的解法选择扮演后手,则该划分即为先手所构造的数对(即数字 i 属于第 pi 个数对);若被 Hack 的解法选择扮演先手,则这些 pi 的具体取值不影响结果,但必须构成 1,2,…,2n 的一个合法划分(即 1 到 n 每个整数恰好出现两次)。
输入输出样例
输入#1
2 1 1 2 2 0
输出#1
Second 1 3
输入#2
2 0
输出#2
First 2 1 2 1
说明/提示
In the first sample, n=2, and you decide to play as Second. The judge chooses the pairs (1,2) and (3,4), and you reply with the numbers 1 and 3. This is a valid choice since it contains exactly one number from each pair, and the sum 1+3=4 is divisible by 4.
In the second sample, n=2 again, and you play as First. You choose the pairs (2,4) and (1,3). The judge fails to choose a number from each pair such that their sum is divisible by 4, so the answer is correct.
Note that the sample tests are just for illustration of the interaction protocol, and don't necessarily correspond to the behavior of the real interactor.
在第一个样例中,n=2,你选择作为后手(Second)进行游戏。裁判选择了数对 (1,2) 和 (3,4),你分别回应数字 1 和 3。这是一个合法的选择,因为它恰好从每个数对中各选了一个数,且其和 1+3=4 能被 4 整除。
在第二个样例中,n=2,你作为先手(First)进行游戏。你选择了数对 (2,4) 和 (1,3)。裁判无法从每个数对中各选出一个数,使得它们的和能被 4 整除,因此该答案是正确的。
注意:这些样例测试仅用于说明交互协议,不一定对应真实交互器的行为。
输入解题思路,AI测评打分。不知道怎么写?