CF1779E.Anya's Simultaneous Exhibition
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
Anya has gathered n chess experts numbered from 1 to n for which the following properties hold:
- For any pair of players one of the players wins every game against the other (and no draws ever occur);
- Transitivity does not necessarily hold — it might happen that A always beats B, B always beats C and C always beats A.
Anya does not know, for each pair, who is the player who beats the other.
To organize a tournament, Anya hosts n−1 games. In each game, she chooses two players. One of them wins and stays, while the other one is disqualified. After all the games are hosted only one player will remain. A player is said to be a candidate master if they can win a tournament (notice that the winner of a tournament may depend on the players selected by Anya in the n−1 games).
Since Anya is a curious girl, she is interested in finding the candidate masters. Unfortunately, she does not have much time. To speed up the process, she will organize up to 2n simuls (short for "simultaneous exhibition", in which one player plays against many).
In one simul, Anya chooses exactly one player who will play against some (at least one) of the other players. The chosen player wins all games they would win in a regular game, and the same holds for losses. After the simul finishes, Anya is only told the total number of games won by the chosen player (but not which ones). Nobody is disqualified during a simul.
Can you help Anya host simuls and determine the candidate masters?
The winning players in each pair could be changed between the simuls, but only in a way that preserves the results of all previous simuls. These changes may depend on your queries.
Interaction
Firstly, the jury sends one integer n (3≤n≤250) which should be read — the number of players. After that, your program may ask queries or report an answer.
To ask a query, print "? is1s2…sn" (without quotes), where i is the index of the player who will play against some of the other players in the simul. s is a binary string that denotes the players they play against. i plays against every player j for which sj=1 holds (and sj=1 should hold for at least one 1≤j≤n). Please note that si=0 must hold since a player cannot play against themselves, otherwise, the query is considered to be incorrect.
After this, you should read an integer — the number of games player i has won.
When you have identified the answer, you must print "! c1c2…cn" (without quotes) and terminate your program. c is a binary string which represents the candidate masters. Player i is a candidate master if ci=1 holds, otherwise, they are not.
If you ask more than 2n queries or if one of the queries is malformed, the interaction terminates immediately and your program receives verdict Wrong Answer.
After printing a query do not forget to output the 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 the documentation for other languages.
Hacks are disabled in this problem.
这是一个交互式问题。
安雅召集了 n 位国际象棋专家,编号为 1 到 n,他们满足如下性质:
- 对于任意一对选手,其中一人总能在所有对局中击败另一人(且永远不会出现平局);
- 传递性不一定成立——可能出现 A 总是击败 B、B 总是击败 C、而 C 又总是击败 A 的情形。
安雅并不知道每一对选手中究竟谁击败谁。
为了组织一场锦标赛,安雅将举办 n−1 场比赛。在每场比赛中,她选择两名选手;其中一人获胜并留下,另一人则被淘汰。当全部 n−1 场比赛结束后,仅剩一名选手。若某位选手存在某种比赛安排方式(即安雅在 n−1 场比赛中依次选择的选手对),使其最终赢得整个锦标赛,则称该选手为候选大师(注意:锦标赛的最终获胜者可能依赖于安雅在 n−1 场比赛中所选定的具体选手对)。
由于安雅是一位充满好奇心的女孩,她希望找出所有候选大师。不幸的是,她时间有限。为了加快进程,她最多将组织 2n 场“车轮战”(simul,即“simultaneous exhibition”的缩写,指一名选手同时与多名对手对弈)。
在一次车轮战中,安雅恰好指定一名选手,该选手将与其余选手中的某些人(至少一人)对弈。该指定选手在车轮战中对每位对手的胜负关系,与其在常规单挑对局中的胜负关系完全一致(即:若在常规对局中他能赢某人,则此处也赢;若输,则此处也输)。车轮战结束后,安雅仅被告知该指定选手总共赢了多少盘棋(但不会告知具体赢了哪几盘)。车轮战过程中无人被淘汰。
你能帮助安雅设计车轮战并确定所有候选大师吗?
每对选手之间的胜负关系可在各次车轮战之间发生变化,但必须保证所有此前已进行的车轮战的结果保持不变。这些变化可依赖于你所提出的查询。
交互流程
首先,评测系统将发送一个整数 n(3≤n≤250),你需要读入它——这表示选手总数。此后,你的程序可以提出查询或报告答案。
要提出一个查询,请输出 "? $i \; s_1 s_2 \ldots s_n$(不带引号),其中 i 是将在本次车轮战中出战的选手编号;s 是一个二进制字符串,用于指示该选手将与哪些其他选手对弈。对每个满足 sj=1 的 j(1≤j≤n),选手 i 将与选手 j 对弈(且至少存在一个 j 满足 sj=1)。请注意:由于选手不能与自己对弈,故必须有 si=0;否则该查询视为非法。
随后,你需要读入一个整数——即选手 i 在本次车轮战中获胜的局数。
当你已确定答案后,必须输出 "! $c_1 c_2 \ldots c_n$(不带引号)并终止程序。c 是一个二进制字符串,用于表示候选大师:若 ci=1,则选手 i 是候选大师;否则不是。
若你提出的查询总数超过 2n 次,或其中任一查询格式错误,则交互立即终止,你的程序将得到“答案错误”(Wrong Answer)判据。
每次输出查询后,请务必输出换行符并刷新输出缓冲区,否则你会收到“空闲超时”(Idleness limit exceeded)错误。为此,请使用:
- C++ 中的
fflush(stdout)或cout.flush(); - Java 中的
System.out.flush(); - Pascal 中的
flush(output); - Python 中的
stdout.flush(); - 其他语言请参阅相应文档。
本题禁用 Hack 功能。
输入输出样例
输入#1
3 1 1 1
输出#1
? 1 010 ? 2 001 ? 3 100 ! 111
输入#2
5 0 3 4
输出#2
? 5 10110 ? 2 10111 ? 1 01111 ! 10000
说明/提示
In the first example, the first query describes a simul in which player 1 plays against player 2 (and no one else). The answer to the query is 1, meaning that player 1 won the only game they played. We can conclude that 1 beats 2. Similarly, the second query tells us that 2 beats 3 and the third query tells us that 3 beats 1. All players are candidate masters in this case as
- Player 1 can win the tournament if 2 and 3 play first. 3 loses and leaves, while 2 stays. 1 then plays against 2 and wins;
- Other players can win in the same fashion.
In the second example, the third query describes a simul in which player 1 plays against every other player. The answer to the query is 4, meaning that they won every game they played. It can be concluded that player 1 also beats every other player. They can never lose, hence they are the only player who can remain at the end of every possible tournament, and the only possible candidate master.
在第一个例子中,第一个查询描述了一场表演赛(simul),其中选手 1 与选手 2 对弈(且无其他选手参与)。该查询的答案为 1,表示选手 1 赢得了他们所进行的唯一一局比赛。由此可推知:1 战胜 2。类似地,第二个查询表明 2 战胜 3,第三个查询表明 3 战胜 1。此时所有选手均为候选大师,因为:
- 若选手 2 与 3 先对弈,则 3 落败离场,2 留下;随后选手 1 与 2 对弈并获胜,因此选手 1 可赢得整场锦标赛;
- 其他选手亦可采用类似方式赢得锦标赛。
在第二个例子中,第三个查询描述了一场表演赛,其中选手 1 与其余所有选手对弈。该查询的答案为 4,表示选手 1 赢得了其参与的所有对局。由此可推知:选手 1 战胜其余所有选手。选手 1 永远不会落败,因此是唯一能在任意可能的锦标赛结束后仍留在场上的选手,也是唯一的可能候选大师。
输入解题思路,AI测评打分。不知道怎么写?