#P10431. [JOIST 2024] 三色灯 / Tricolor Lights

    ID: 13368 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024交互题Special Judge通信题JOISC/JOIST(日本)

[JOIST 2024] 三色灯 / Tricolor Lights

Description

Anna and Bruno, experts in gambling, are about to compete against Dealer D-taro in a game. During the game, Anna and Bruno are isolated in separate rooms and can only communicate through Dealer D-taro.

In this game, they use a row of NN lights. These lights are numbered from 1 to NN from left to right and can be illuminated in one of three colors: red, green, or blue.

At the beginning of the game, Anna illuminates each of these lights in either red, green, or blue. Additionally, Dealer D-taro specifies one prohibited color for each light, represented by a string SS of length NN. Let SiS_i denote the ii-th character of SS (1iN1 \le i \le N). If SiS_i is 'R', the prohibited color for light ii is red; if SiS_i is 'G', it's green; and if SiS_i is 'B', it's blue. Anna cannot illuminate light ii in its prohibited color. For example, if SiS_i is 'R', Anna cannot illuminate light ii in red. Dealer D-taro conveys the information of the prohibited color for each light to Anna but not to Bruno.

After illuminating each light, Anna selects an integer ll satisfying 1lmin(N,130)1 \le l \le \min(N, 130) and informs Dealer D-taro. Dealer D-taro then informs Bruno of the total number of lights NN and the integer ll chosen by Anna. Subsequently, they proceed with QQ rounds as follows:

  1. Dealer D-taro selects an integer aja_j between 1 and Nl+1N - l + 1 and shows Bruno the sequence of colors illuminated for lights aj,aj+1,,aj+l1a_j, a_j+1, \ldots, a_j+l-1.
  2. Bruno responds with a single integer to Dealer D-taro based on the sequence of colors shown. If the integer matches aja_j, Anna and Bruno win the round.

However, Dealer D-taro may vary the selection of a1,a2,,aQa_1, a_2, \ldots, a_Q based on the sequence of colors illuminated by Anna and the chosen integer ll.

You are required to implement a program that allows Anna and Bruno to win all QQ rounds.

Implementation Details

You need to submit 2 files.

The first file is Anna.cpp. It should implement Anna's strategy. It should implement the following functions. The program should include Anna.h using the preprocessing directive #include.

  • std::pair<std::string, int> anna(int N, std::string S) This function is called once initially.
    • The parameter NN is the number of lights.
    • The parameter SS is a string of length NN representing the prohibited colors specified by Dealer D-taro.
    • The return value is a pair consisting of a string tt representing the colors Anna illuminates for each light and an integer ll chosen by Anna. Let tit_i denote the ii-th character of tt (1iN1 \le i \le N). tit_i signifies Anna illuminating the ii-th lamp with color tit_i. If tit_i is 'R', the prohibited color for light ii is red; if tit_i is 'G', it's green; and if tit_i is 'B', it's blue.
    • The length of string tt must be NN. Otherwise, it will be judged as Wrong Answer [1].
    • Each character in string tt must be 'R', 'G', or 'B'. Otherwise, it will be judged as Wrong Answer [2].
    • Each character tit_i must be different from the corresponding character in SS. Otherwise, it will be judged as Wrong Answer [3].
    • ll must be between 1 and min(N,130)\min(N, 130). Otherwise, it will be judged as Wrong Answer [4].

The second file is Bruno.cpp. It should implement Bruno's strategy. It should implement the following functions. The program should include Bruno.h using the preprocessing directive #include.

  • void init(int N, int l) This function is called once initially.
    • The parameter NN is the number of lights.
    • The parameter ll is the integer chosen by Anna.
  • int bruno(std::string u) This function is called QQ times after function init is called and corresponds to steps 1 and 2 of each round in the game.
    • The argument uu is a string of length ll consisting of 'R', 'G', 'B', representing the sequence of colors illuminated for lights aj,aj+1,,aj+l1a_j, a_j+1, \ldots, a_j+l-1.
    • Let uku_k denote the kk-th character of uu (1kl1 \le k \le l). If uku_k is 'R', the color of aj+k1a_j+k-1-th light that Anna illuminated is red; if uku_k is 'G', it's green; and if uku_k is 'B', it's blue.
    • The return value is the integer Bruno responds with.
    • The return value must match aja_j. Otherwise, it will be judged as Wrong Answer [5].

Important Notices

  • Your program can implement other functions for internal use, or use global variables. Submitted files will be compiled with the grader, and become a single executable file. All global variables and internal functions should be declared in an unnamed namespace to avoid confliction with other files. When it is graded, it will be executed as two processes of Anna and Bruno. The process of Anna and the process of Bruno cannot share global variables.
  • Your program must not use the standard input and the standard output. Your program must not communicate with other files by any methods. However, your program may output debugging information to the standard error.

Compilation and Test Run

You can download an archive file from the contest webpage which contains the sample grader to test your program.

The sample grader is the file grader.cpp. In order to test your program, put grader.cpp, Anna.cpp, Bruno.cpp, Anna.h, Bruno.h in the same directory, and run the following command to compile your programs. Instead, you may run compile.sh contained in the archive file.

g++ -std=gnu++20 -O2 -o grader grader.cpp Anna.cpp Bruno.cpp

When the compilation succeeds, the executable file grader is generated.

Note that the actual grader is different from the sample grader. The sample grader will be executed as a single process, which will read input data from the standard input and write the results to the standard output and the standard error output.

Grading Considerations

The actual grading program determines a1,a2,,aQa_1, a_2, \ldots, a_Q based on the sequence of colors illuminated by Anna and the chosen integer ll. But Bruno's response does not affect the selection of a1,a2,,aQa_1, a_2, \ldots, a_Q.

Input Format

The sample grader reads the following data from the standard input.

NN
SS
QQ
a1a_1 a2a_2 \cdots aQa_Q

Unlike the actual grading program, the sample grading program must have fixed answers. aja_j (1jQ1 \le j \le Q) represents the integer aja_j chosen by Dealer D-taro in the jj-th round. In your program, aja_j must satisfy 1ajNl+11 \le a_j \le N - l + 1 for the integer ll chosen by Anna.

Output Format

The sample grader outputs the following information to the standard output and the standard error output (quotes for clarity).

  • For correct answers, “Accepted: l\texttt{Accepted: l}” is output for the integer ll chosen by Anna.
  • For wrong answers, the type of wrongness is output, such as “Wrong Answer [1]”.

If your program meets the conditions of several types of Wrong Answer, the sample grader reports only one of them.

8
RGGBRBBG
2
3 1

Hint

Constraints

  • 1N5000001 \le N \le 500\,000.
  • 1Q100001 \le Q \le 10\,000.
  • SS is a string of length NN consisting of 'R', 'G', or 'B'.
  • NN and QQ are integers.

Subtasks

  1. (5 points) N131N \le 131.

  2. (5 points) N250N \le 250.

  3. (5 points) N380N \le 380.

  4. (15 points) N7000N \le 7\,000.

  5. (70 points) No additional constraints. In this subtask, points are awarded as follows:

    • Let ll^* denote the maximum value of ll chosen by Anna in all test cases of this subtask.
    • If any test case in this subtask is judged as Wrong Answer [1] ~ [5] (see implementation details) or exceeds the time limit, memory limit, or encounters a runtime error, the subtask score is 0 points.
    • If all test cases in this subtask are correct, the subtask score is determined as follows:
    the value of ll^* score
    61<l13061 < l^* \le 130 10 points
    41<l6141 < l^* \le 61 20 points
    34<l4134 < l^* \le 41 25 + 3 x (41l)(41 - l^*) points
    28<l3428 < l^* \le 34 46 + 4 x (34l)(34 - l^*) points
    l28l^* \le 28 70 points

Sample Communication

Here is a sample input for the sample grader and corresponding function calls.

Sample Function Calls

Sample Input 1 Call Return value
$\texttt{8}\\\texttt{RGGBRBBG}\\\texttt{2}\\\texttt{3 1}$ anna(8, "RGGBRBBG") ("BBRGBGRR", 5)
^ init(8, 5)
bruno("RGBGR") 3
bruno("BBRGB") 1

In this example, Anna receives the number of lights N=8N = 8 and the string representing prohibited colors S="RGGBRBBC"S = \text{"RGGBRBBC"}. Anna chooses to illuminate each light with the string tt representing colors "BBRGBGRR"\text{"BBRGBGRR"} and selects the integer ll as 5, which she communicates to Dealer D-taro. Then, Dealer D-taro informs Bruno of the numbers N=8N = 8 and l=5l = 5.

In the first round, Dealer D-taro chooses a1=3a_1 = 3. Bruno receives the sequence of colors illuminated for lights 3, 4, 5, 6, and 7, represented by the string u="RGBGR"u = \text{"RGBGR"}, and responds with the integer 3, which matches a1a_1. Input example 1 satisfies all constraints for all subtasks. The file sample-01-in.txt downloadable from the contest site corresponds to input example 1.