| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 256 MB | 140 | 15 | 15 | 14.851% |
Anna and Bruno are archaeologists. They excavate ruins of IOI Kingdom. In the ruin A, Anna discovered the layout of an old machine. In the ruin B, Bruno discovered the actual machine.
This machine consists of N devices. The devices are attached to an electric wire in a row. There are three types of devices called X, Y, Z. From the left, the devices are numbered from 0 through N − 1. The type of the device i (0 ≤ i ≤ N − 1) is Si. In other words, Si is either X, Y, or Z.
Since the machine is too big, Bruno decided to remove the devices, one by one, from the machine. However, since the devices interact with each other by an electric wire, he must be very careful about the order of removal.
Concerning a way to remove a device from the machine, we define the following.
Bruno has to remove all of the N devices from the machine so that the number of good removals is the maximum possible. However, since the three types of devices look similar, he cannot distinguish the types of the devices.
Since Anna has the layout of the machine, she knows the type of each device attached to the machine. Thus, she will use a transmitter to help Bruno. Using the transmitter, she can send a sequence of characters. Each character she can send is either 0 or 1.
Write a program which implements Anna’s strategy and Bruno’s strategy so that the number of good removals is the maximum possible. In this task, if the number of characters sent by Anna to Bruno is smaller, your will get higher score.
You need to submit two files.
The first file is Anna.cpp. It should implement Anna’s strategy. It should implement the following function. The program should include Anna.h using the preprocessing directive #include.
void Anna(int N, std::vector<char> S)N is the number of devices N.S is an array of length N. This means S[i] is the type Si of the device i (0 ≤ i ≤ N − 1). Here the character S[i] is either ‘X’, ‘Y’, or ‘Z’.Your program can call the following function.
void Send(int a)a is an information sent to Bruno. It should be 0 or 1. If this condition is not satisfied, your program is judged as Wrong Answer [1].Send should not be called more than 200 000 times. If it is called more than 200 000 times, your program is judged as Wrong Answer [2].The second file is Bruno.cpp. It should implement Bruno’s strategy. It should implement the following function. The program should include Bruno.h using the preprocessing directive #include.
void Bruno(int N, int L, std::vector<int> A)N is the number of devices N.L is the number L of characters, 0 or 1, sent by Anna.A is an array of length L. It means Anna sent the sequence A[0],A[1],...,A[L-1] of characters to Bruno, in this order. Each character of the sequence is either 0 or 1.Your program can call the following function.
void Remove(int d)d is the index of a device. It means Bruno removes the device d.Remove should be called exactly N times. When the function Bruno terminates, if the number of calls to the function Remove is different from N, your program is judged as Wrong Answer [5].The sample grader reads the following data from the standard input.
N S0 S1 · · · SN−1
Here Si and Si+1 (0 ≤ i ≤ N − 2) are separated by a space.
When the program terminates successfully, the sample grader writes the following information to the standard output (quotes for clarity).
Wrong Answer [1]”.Accepted: L D”. Note that the behavior of the sample grader is different from the actual grader. The sample grader does not check whether your program is judged as Wrong Answer [6] or not.If your program is judged as several types of Wrong Answer [1], [2], [3], [4], or [5], the sample grader reports only one of them.
X, Y, or Z (0 ≤ i ≤ N − 1).N ≤ 18.
No additional constraints. In this Subtask, your score is calculated by the following way.
Here ⌊x⌋ is the largest integer not exceeding x.
Here is a sample input for the sample grader and corresponding function calls.
| Sample Input 1 | Sample Function Calls | |
|---|---|---|
| Call | Call | |
4 X Y X Z |
Anna(4, {X, Y, X, Z}) |
|
Send(0) |
||
Send(1) |
||
Bruno(4, 2, {0, 1}) |
||
Remove(2) |
||
Remove(1) |
||
Remove(0) |
||
Remove(3) |
||
In these sample function calls, the 4 devices will be removed by the following way.
X Y X Z.X Y - Z. Here - means the device in this position was already removed.X - - Z. Since (x, y,z) = (0, 1, 3) satisfies the condition, it is a good removal.- - - Z.- - - -. The number of good removals is 1.In this sample input, the number of good removals cannot be greater than 1.
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)