#P9269. [CEOI 2013] 新宝岛 / Treasure
[CEOI 2013] 新宝岛 / Treasure
Background
Translated from CEOI 2013 Day 1.
This is an interactive IO task.
After an earthquake, a new island appeared in the Adriatic Sea. A special device was found on the island, called the “Oracle”. Although there was no manual, a team of archaeologists and computer experts managed to understand how it works.
The Oracle provides some information about the locations of treasures on the island. The island is divided into an by grid, with both rows and columns numbered from to . Some cells in the grid contain treasures. The Oracle only answers questions of the following form: “Given a rectangle in the grid, how many cells in this rectangle contain treasures?”
Although the Oracle can answer rectangle queries of any size, it was discovered that the more specific the requested information is (the smaller the rectangle is), the more energy the Oracle consumes when answering. More precisely, if a rectangle contains cells, then the Oracle will use units of energy to answer.
Problem Description
Write a program that determines the positions of all cells on the island that contain treasures by interacting with the Oracle. We do not want to use too much energy during this process: the less energy used, the better. However, you are not required to minimize the energy usage; see “Hint” at the end for the scoring rules.
This is an interactive task. Your program asks the Oracle by writing to standard output, and obtains answers by reading from standard input.
- At the start of the program, it should read an integer (), the size of the grid.
- To ask the Oracle, your program should output one line containing integers , , , and , separated by spaces, such that and . If these conditions do not hold, or the line format is incorrect, your program will receive points on that test run.
- The Oracle will respond with a line containing a single integer: the number of cells containing treasures inside the given rectangle. More precisely, it is the number of cells such that and , and the cell in row and column contains a treasure.
- When the program finishes asking questions (i.e., it has determined the positions of all treasures), it should output
ENDon a new line. Then output lines, each a string of characters0or1. The -th character of line is1if the cell in row and column contains a treasure, and0otherwise. Rows are numbered from top to bottom as to , and columns are numbered from left to right. Once your program outputs the solution, its execution will be terminated automatically.
To interact correctly with the judge, you must flush standard output after each query and after printing the final solution, as is customary for interactive tasks.
In each test run, you may assume the Oracle always answers correctly, and the treasure locations are fixed before interaction. In other words, the answers do not depend on the questions previously asked (the Oracle will not change the answer based on your queries); the correct grid is fixed for each test case.
Input Format
This task is an interactive task. To complete it successfully, you need to write a program to minimize the number of queries to the Oracle and the energy used as much as possible. At the start of the program, the input provides the island size .
Output Format
Query the Oracle for the number of treasure cells by outputting row and column indices. After your program has obtained enough information, output END, then output the final grid of treasure positions. The final score is determined by the total energy used by the Oracle. The exact scoring rules are given at the end of the statement, and the detailed format can be seen in the sample input/output.
2
0
1
2
1 1 1 1
1 2 1 2
2 1 2 2
END
01
11
Hint
Each test case is worth points. If your program’s output is incorrect, it gets points for that test case. Otherwise, the score is determined by the total number of energy units used by the Oracle, denoted by .
Specifically:
- If , you get points.
- Otherwise, if , you get points.
- Otherwise, if , you get points.
- Otherwise, if , you get point.
- Otherwise, you get points.
Also, in testdata that accounts for at least of the total score, will be at most .
In summary, the less energy you spend, the higher your score will be.
Interactive library / SPJ provider:
Translated by ChatGPT 5