QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100 コミュニケーション

#1419. Messenger

統計

A and B, who have been selected as representatives of Japan for the International Olympiad in Informatics, have decided to play the "Messenger Game" with Director K of the Japanese Committee for the International Olympiad in Informatics to improve their information processing skills. The rules of this game are explained below.

A and B are isolated in rooms as shown in the figure. Although there are internal telephones in the rooms of A, B, and Director K, only Director K can initiate a call. Other means of communication are cut off, and A and B cannot leave their rooms unless instructed.

A's room | Long corridor | Director K's room | Long corridor | B's room

At the start of the game, Director K tells A a positive integer $X$ over the phone. The goal of the game is for A to correctly convey the value of $X$ to B without direct communication between them.

Director K's room has a $4 \times 4$ grid. Let $(i, j)$ represent the cell in the $i$-th row and $j$-th column ($1 \le i \le 4, 1 \le j \le 4$). Cell $(1, 1)$ is the top-left corner, $(1, 4)$ is the top-right corner, $(4, 1)$ is the bottom-left corner, and $(4, 4)$ is the bottom-right corner. At the start of the game, a piece is placed in one of the cells. Thereafter, Director K will not change the cell where the piece is placed.

From this point on, Director K repeatedly calls either A or B to the room by phone. Every time A or B comes to Director K's room, they must move the piece to an adjacent cell (up, down, left, or right). After moving the piece, A or B returns to their own room. If B knows the value of $X$ when coming to Director K's room, B can answer it to Director K instead of moving the piece. If the correct value of $X$ is answered, it is a correct answer; otherwise, it is an incorrect answer.

The timing at which Director K calls A or B to the room is irregular, and A and B do not know the order in which Director K is calling the two to the room. However, Director K decides the order in which to call the two at the start of the game, and it is guaranteed that Director K will not call either A or B more than 100 times in a row. If B has not answered the value of $X$ after A or B has returned to their room after Director K has called A and B a total of 10,000 times, the game ends as an incorrect answer.

Task

Implement the strategies for A and B, and create a program that can answer correctly in the "Messenger Game" described above.

Implementation Details

You must submit two files in the same programming language.

The first file is named playerA.c or playerA.cpp. This file implements A's strategy and must implement the following routines:

  • void InitA(int T, int X) This routine is called exactly once at the beginning. The argument T is the subtask number. The argument X is the positive integer that A must convey to B.

  • int GameA(int I, int J) This routine is called when A comes to Director K's room. The arguments I and J are the integers representing the cell $(I, J)$ where the piece is located when A arrives at Director K's room, satisfying $1 \le I \le 4$ and $1 \le J \le 4$. This routine must return one of the integers $-1, -2, -3, -4$. If any other value is returned, it is judged as Wrong Answer [1] and the program execution is terminated. These represent the following actions by A:

    • $-1$: Move the piece to the cell above $(I - 1, J)$.
    • $-2$: Move the piece to the cell below $(I + 1, J)$.
    • $-3$: Move the piece to the cell to the left $(I, J - 1)$.
    • $-4$: Move the piece to the cell to the right $(I, J + 1)$. If a move that takes the piece outside the board is specified, it is judged as Wrong Answer [2] and the program execution is terminated.

The second file is named playerB.c or playerB.cpp. This file implements B's strategy and must implement the following routines:

  • void InitB(int T) This routine is called exactly once at the beginning. The argument T is the subtask number.

  • int GameB(int I, int J) This routine is called when B comes to Director K's room. The arguments I and J are the integers representing the cell $(I, J)$ where the piece is located when B arrives at Director K's room, satisfying $1 \le I \le 4$ and $1 \le J \le 4$. This routine must return one of the integers $-1, -2, -3, -4$, or a positive integer $Y$. If any other value is returned, it is judged as Wrong Answer [3] and the program execution is terminated. These represent the following actions by B:

    • $-1$: Move the piece to the cell above $(I - 1, J)$.
    • $-2$: Move the piece to the cell below $(I + 1, J)$.
    • $-3$: Move the piece to the cell to the left $(I, J - 1)$.
    • $-4$: Move the piece to the cell to the right $(I, J + 1)$. If a move that takes the piece outside the board is specified, it is judged as Wrong Answer [4] and the program execution is terminated.
    • Positive integer $Y$: Answer to Director K that the value of $X$ is $Y$. If $X = Y$, it is a correct answer; otherwise, it is judged as Wrong Answer [5] and the program execution is terminated.

The routines GameA and GameB will not be called more than 100 times in a row for either one. Also, if GameB has not returned a positive integer by the time GameA and GameB have been called a total of 10,000 times, it is judged as Wrong Answer [6] and the program execution is terminated.

You are free to implement other routines or declare global variables for internal use. However, since the two submitted programs are linked together with the grader program into a single executable file, you must declare all global variables and internal routines in each file as static to avoid interference with other files. During grading, this program is executed as two separate processes, one for A and one for B, so global variables cannot be shared between the A side and the B side. Your submission must not interact with standard input/output or any other files in any way.

Input

The sample grader reads the following input from standard input:

  • The first line contains integers $T, X, I_0, J_0$ separated by spaces, representing the subtask number $T$, the integer $X$ that A must convey to B, and the initial position $(I_0, J_0)$ of the piece at the start of the game.
  • The second line contains a string of length exactly 10,000 consisting of two types of characters, 'A' and 'B'. If the $k$-th character ($1 \le k \le 10,000$) is 'A' or 'B', it means that the $k$-th routine called after InitA and InitB are called is GameA or GameB, respectively.

Output

If the program terminates normally, the sample grader outputs the following information to standard output in one line:

  • If correct, "Accepted" is output (quotation marks are not actually output; the same applies below).
  • If incorrect, the type of incorrect answer is output as "Wrong Answer [1]" based on the numbers written in the "Implementation Details" section. Furthermore, for Wrong Answer [5], the correct value of $X$ and the positive integer $Y$ returned by the routine GameB are output as "Wrong Answer [5] : X = 2, Y = 3".

Constraints

All input data satisfy the following conditions:

  • $1 \le X \le 1,000,000,000$.

Subtasks

Subtask 1 [20 points]

  • Satisfies $T = 1$.
  • A is called to Director K's room first, and A and B are called to Director K's room alternately. That is, after InitA and InitB are called, the routines are called in the order GameA, GameB, GameA, GameB, ...

Subtask 2 [20 points]

  • Satisfies $T = 2$.
  • The position of the piece at the start of the game is $(I_0, J_0) = (1, 1)$. That is, after InitA and InitB are called, first the routine GameA or GameB is called with $I = 1, J = 1$ as arguments.

Subtask 3 [60 points]

  • Satisfies $T = 3$.

Note

An example of the input read by the sample grader and an example of the corresponding routine calls are shown below.

Input
2 6 1 1
ABBAABAAABBBBBABBAABBBABBBBAAAAABABAABAABBBBABAAAA (omitted)
A side B side
Call Return Call Return
InitA(2, 6) None
InitB(2) None
GameA(1, 1) -2
GameB(2, 1) -4
GameB(2, 2) -2
GameA(3, 2) -3
GameA(3, 1) -1
GameB(2, 1) 6

Note that this example does not necessarily describe a meaningful interaction.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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 1
IDTypeStatusTitlePosted ByLast UpdatedActions
#451General DiscussionOpenFix the graderQingyu2025-12-23 17:21:34View

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.