CF1147F.Zigzag Game

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a complete bipartite graph with 2n2n nodes, with nn nodes on each side of the bipartition. Nodes 11 through nn are on one side of the bipartition, and nodes n+1n+1 to 2n2n are on the other side. You are also given an n×nn \times n matrix aa describing the edge weights. aija_{ij} denotes the weight of the edge between nodes ii and j+nj+n. Each edge has a distinct weight.

Alice and Bob are playing a game on this graph. First Alice chooses to play as either "increasing" or "decreasing" for herself, and Bob gets the other choice. Then she places a token on any node of the graph. Bob then moves the token along any edge incident to that node. They now take turns playing the following game, with Alice going first.

The current player must move the token from the current vertex to some adjacent unvisited vertex. Let ww be the last weight of the last edge that was traversed. The edge that is traversed must be strictly greater than ww if the player is playing as "increasing", otherwise, it must be strictly less. The first player unable to make a move loses.

You are given nn and the edge weights of the graph. You can choose to play as either Alice or Bob, and you will play against the judge. You must win all the games for your answer to be judged correct.

Interaction

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤501 \le t \le 50). Description of the test cases follows.

Each test starts with an integer nn (1≤n≤501 \leq n \leq 50) — the number of nodes on each side of the bipartition.

The next nn lines contain nn integers aija_{ij} (1≤aij≤n21 \leq a_{ij} \leq n^2). aija_{ij} denotes the weight of the edge between node ii and node j+nj+n. All aija_{ij} will be distinct.

You first print a string "A" or "B", denoting which player you want to play ("A" for Alice and "B" for Bob).

If playing as Alice, first print either "I" or "D" (denoting whether you choose "increasing" or "decreasing"). Then, print the node that you wish to start at.

If playing as Bob, read in a character "I" or "D" (denoting whether the judge chose "increasing" or "decreasing"), then the node that the judge chooses to start at.

To make a move, print the index of the node that you wish to go to. To read what move the judge made, read an integer from standard in.

If the judge responds with −1-1, then that means the judge has determined it has no legal moves (or it may have just given up) and that you won the case. Stop processing this case immediately and start processing the next case.

If the judge responds with −2-2, that means that the judge has determined that you made an invalid move, so you should exit immediately to avoid getting other verdicts.

If you are unable to make a move or give up, print −1-1 and then exit immediately. This will give you a Wrong answer verdict.

After printing a move 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. Note that you can only hack with one test case.

The first line should contain a single integer tt (t=1t=1).

The second line should contain an integer nn (1≤n≤501 \leq n \leq 50).

The next nn lines should contain nn integers each, the aija_{ij} (1≤aij≤n21 \leq a_{ij} \leq n^2). aija_{ij} denotes the weight of the edge between node ii and node j+nj+n. All aija_{ij} must be distinct.

The judge will play a uniformly random legal move with this case versus the hacked program. If it has no legal moves left, it will give up and declare the player as the winner.

你被给定一个包含 2n2n 个节点的完全二分图,二分图的每一侧各有 nn 个节点。编号为 11 到 nn 的节点位于二分图的一侧,编号为 n+1n+1 到 2n2n 的节点位于另一侧。你还被给定一个 n×nn \times n 的矩阵 aa,用于描述边的权重:aija_{ij} 表示节点 ii 与节点 j+nj+n 之间的边的权重。每条边的权重互不相同。

爱丽丝(Alice)和鲍勃(Bob)正在该图上进行一场游戏。首先,爱丽丝选择自己扮演“递增”(increasing)或“递减”(decreasing)角色,鲍勃则自动获得另一角色。接着,爱丽丝将一个标记(token)放置在图中任意一个节点上;随后鲍勃必须沿一条与该节点关联的边移动该标记。此后双方轮流进行如下操作,且爱丽丝先手:

当前玩家必须将标记从当前顶点沿一条边移动至某个未访问过的相邻顶点。设 ww 为上一次所经过边的权重,则本次所选边的权重必须满足:若该玩家扮演“递增”,则其权重必须严格大于 ww;否则(即扮演“递减”),其权重必须严格小于 ww。首位无法进行合法移动的玩家判负。

你被给定 nn 及图中所有边的权重。你可以选择作为爱丽丝或鲍勃进行游戏,并将与评测程序(judge)对战。为使你的解答被判为正确,你必须赢得所有测试用例。

交互方式

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤501 \le t \le 50)。随后是各测试用例的描述。

每个测试用例以一个整数 nn(1≤n≤501 \leq n \leq 50)开始,表示二分图每侧的节点数。

接下来 nn 行,每行包含 nn 个整数 aija_{ij}(1≤aij≤n21 \leq a_{ij} \leq n^2),其中 aija_{ij} 表示节点 ii 与节点 j+nj+n 之间边的权重。所有 aija_{ij} 均互不相同。

你首先输出一个字符串 "A" 或 "B",表示你希望扮演的角色("A" 表示爱丽丝,"B" 表示鲍勃)。

  • 若你选择扮演爱丽丝,则需先输出字符 "I" 或 "D"(分别表示你选择“递增”或“递减”),然后输出你希望起始放置标记的节点编号。
  • 若你选择扮演鲍勃,则需先读入一个字符 "I" 或 "D"(表示评测程序为你选择的角色),再读入评测程序选定的起始节点编号。

每次进行移动时,输出你希望移动至的目标节点编号(即节点索引)。每次对手(评测程序)移动后,你需要从标准输入读取一个整数,以获知其移动的目标节点。

  • 若评测程序返回 −1-1,表示其判定已无合法移动可走(或主动认输),你赢得本测试用例。请立即停止处理当前用例,并开始处理下一个用例。
  • 若评测程序返回 −2-2,表示其判定你执行了非法移动,此时你应立即退出程序,以免收到其他错误提示。
  • 若你无法进行合法移动或主动认输,请输出 −1-1 并立即退出。这将导致“答案错误”(Wrong answer)判决。

每次输出移动操作后,务必输出换行符并刷新输出缓冲区。否则你会收到“空闲超时”(Idleness limit exceeded)提示。刷新方法如下:

  • C++ 中使用 fflush(stdout) 或 cout.flush();
  • Java 中使用 System.out.flush();
  • Pascal 中使用 flush(output);
  • Python 中使用 stdout.flush();
  • 其他语言请查阅相应文档。

Hack 格式(用于构造测试数据)

要 hack(提供自定义测试数据),请使用以下格式。注意:你仅能提交一个测试用例。

第一行应为单个整数 tt(t=1t = 1)。

第二行为一个整数 nn(1≤n≤501 \leq n \leq 50)。

接下来 nn 行,每行含 nn 个整数,即 aija_{ij}(1≤aij≤n21 \leq a_{ij} \leq n^2),其中 aija_{ij} 表示节点 ii 与节点 j+nj+n 之间边的权重。所有 aija_{ij} 必须互不相同。

评测程序将针对该测试用例,以均匀随机的方式选择一个合法移动,与被 hack 的程序对战。若评测程序已无合法移动,则会主动认输,并宣布当前轮到行动的玩家获胜。

输入输出样例

  • 输入#1

    2
    3
    3 1 9
    2 5 7
    6 4 8
    6
    -1
    1
    1
    I 1
    -1

    输出#1

    A
    D 3
    2
    B
    2

说明/提示

The first example has two test cases. In the first test case, the graph looks like the following.

In the sample output, the player decides to play as Alice and chooses "decreasing" and starting at node 33. The judge responds by moving to node 66. After, the player moves to node 22. At this point, the judge has no more moves (since the weight must "increase"), so it gives up and prints −1-1.

In the next case, we have two nodes connected by an edge of weight 11. The player decides to play as Bob. No matter what the judge chooses, the player can move the token to the other node and the judge has no moves so will lose.

第一个样例包含两个测试用例。在第一个测试用例中,图的结构如下所示:

在样例输出中,玩家选择扮演 Alice,并选定策略为“递减”,且从节点 33 开始。裁判响应,将标记移动到节点 66;随后玩家将标记移动到节点 22。此时裁判已无合法移动(因为边权必须“递增”),于是认输并输出 −1-1。

在下一个测试用例中,图中仅有两个节点,由一条权重为 11 的边相连。玩家选择扮演 Bob。无论裁判如何选择,玩家均可将标记移至另一节点,此时裁判已无合法移动,因而失败。

输入解题思路,AI测评打分。不知道怎么写?

首页