Ancient Machine
Time limit2sMemory limit256 MB
Anna sees the X, Y, Z layout and sends 0/1 bits so Bruno can remove every device in an order that maximizes good removals, using as few bits as possible.
- Level
Hard8 of 10
- Topics
- String, Greedy, Implementation
- Solved
- No attempts yet
Problem
Anna and Bruno are archaeologists. They excavate the ruins of the IOI Kingdom. At ruin A, Anna discovered the layout of an old machine. At ruin B, Bruno discovered the actual machine.
The machine consists of devices attached to an electric wire in a row. There are three device types, X, Y, and Z. The devices are numbered from 0 to from the left. The type of device is , which is X, Y, or Z.
The machine is too big, so Bruno decided to remove the devices one by one. The devices interact through the electric wire, so he must be careful about the removal order.
A removal is defined as follows.
- Suppose devices , , () are not yet removed, is
X, isY, and isZ. Also suppose every device with is already removed, and every device with is already removed. If all these conditions hold and device is removed, this is called a good removal. - Any other removal is not a good removal.
Bruno must remove all devices so that the number of good removals is as large as possible. However, the three device types look alike, so Bruno cannot tell the types apart.
Anna knows the type of each device because she has the layout. She uses a transmitter to help Bruno. Through the transmitter, she can send a sequence of characters, each either 0 or 1.
Write a program that implements Anna's strategy and Bruno's strategy so that the number of good removals is maximized. Anna gets a higher score the fewer characters she sends.
Input
The sample grader reads the following data from standard input.
N
S0 S1 ... SN-1
and () are separated by a space.
Output
When the program terminates successfully, the sample grader writes the following information to standard output (quotes are added for clarity).
- If your program is judged as any one of Wrong Answer [1], [2], [3], [4], or [5], it writes its type as
Wrong Answer [1]. - Otherwise, it writes the number of calls to Send and the number of good removals as
Accepted: L D.
The sample grader behaves differently from the actual grader. It does not check whether your program is judged as Wrong Answer [6].
If your program falls under several of Wrong Answer [1], [2], [3], [4], or [5], the sample grader reports only one of them.
Constraints
- .
- is one of
X,Y, orZ().