#P10431. [JOIST 2024] 三色灯 / Tricolor Lights
[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 lights. These lights are numbered from 1 to 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 of length . Let denote the -th character of (). If is 'R', the prohibited color for light is red; if is 'G', it's green; and if is 'B', it's blue. Anna cannot illuminate light in its prohibited color. For example, if is 'R', Anna cannot illuminate light 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 satisfying and informs Dealer D-taro. Dealer D-taro then informs Bruno of the total number of lights and the integer chosen by Anna. Subsequently, they proceed with rounds as follows:
- Dealer D-taro selects an integer between 1 and and shows Bruno the sequence of colors illuminated for lights .
- Bruno responds with a single integer to Dealer D-taro based on the sequence of colors shown. If the integer matches , Anna and Bruno win the round.
However, Dealer D-taro may vary the selection of based on the sequence of colors illuminated by Anna and the chosen integer .
You are required to implement a program that allows Anna and Bruno to win all 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 is the number of lights.
- The parameter is a string of length representing the prohibited colors specified by Dealer D-taro.
- The return value is a pair consisting of a string representing the colors Anna illuminates for each light and an integer chosen by Anna. Let denote the -th character of (). signifies Anna illuminating the -th lamp with color . If is 'R', the prohibited color for light is red; if is 'G', it's green; and if is 'B', it's blue.
- The length of string must be . Otherwise, it will be judged as Wrong Answer [1].
- Each character in string must be 'R', 'G', or 'B'. Otherwise, it will be judged as Wrong Answer [2].
- Each character must be different from the corresponding character in . Otherwise, it will be judged as Wrong Answer [3].
- must be between 1 and . 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 is the number of lights.
- The parameter is the integer chosen by Anna.
int bruno(std::string u)This function is called times after functioninitis called and corresponds to steps 1 and 2 of each round in the game.- The argument is a string of length consisting of 'R', 'G', 'B', representing the sequence of colors illuminated for lights .
- Let denote the -th character of (). If is 'R', the color of -th light that Anna illuminated is red; if is 'G', it's green; and if is 'B', it's blue.
- The return value is the integer Bruno responds with.
- The return value must match . 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 based on the sequence of colors illuminated by Anna and the chosen integer . But Bruno's response does not affect the selection of .
Input Format
The sample grader reads the following data from the standard input.
Unlike the actual grading program, the sample grading program must have fixed answers. () represents the integer chosen by Dealer D-taro in the -th round. In your program, must satisfy for the integer 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, “” is output for the integer 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
- .
- .
- is a string of length consisting of 'R', 'G', or 'B'.
- and are integers.
Subtasks
-
(5 points) .
-
(5 points) .
-
(5 points) .
-
(15 points) .
-
(70 points) No additional constraints. In this subtask, points are awarded as follows:
- Let denote the maximum value of 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 score 10 points 20 points 25 + 3 x points 46 + 4 x points 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 and the string representing prohibited colors . Anna chooses to illuminate each light with the string representing colors and selects the integer as 5, which she communicates to Dealer D-taro. Then, Dealer D-taro informs Bruno of the numbers and .
In the first round, Dealer D-taro chooses . Bruno receives the sequence of colors illuminated for lights 3, 4, 5, 6, and 7, represented by the string , and responds with the integer 3, which matches . 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.
京公网安备 11011102002149号