#P9269. Treasure Grid Oracle Interaction
Treasure Grid Oracle Interaction
Treasure Grid Oracle Interaction
You are on an island where some cells contain treasures. Your task is to determine the location of all treasure cells by interacting with the oracle. Your program will be allowed to ask queries about rectangular subregions of the grid and receive the number of treasure cells within that subregion. Energy consumption is a factor – the fewer queries you make, the better your score. (However, an optimal number of queries is not required.)
This is an interactive problem. At the beginning, your program must read an integer \(N\) (with \(2 \le N \le 100\)) indicating the size of the grid. Then, through standard output, your program may ask questions by printing a line with four integers \(R_1\), \(C_1\), \(R_2\), and \(C_2\), separated by spaces, satisfying \(1 \le R_1 \le R_2 \le N\) and \(1 \le C_1 \le C_2 \le N\). The oracle will respond with a single integer on a line: the number of treasure cells in the rectangle defined by \(R_1 \le R \le R_2\) and \(C_1 \le C \le C_2\).
When you have determined the location of all treasures, your program must output a line containing the word END and then output \(N\) lines. Each of these \(N\) lines must be a string consisting of exactly \(N\) characters that are either '0' or '1'. For the \(R\)-th row, the \(C\)-th character should be '0' if the cell at row \(R\) and column \(C\) contains a treasure, and '1' otherwise.
Note: In interactive problems, you must flush the standard output after every query and final answer to ensure proper communication with the oracle.
inputFormat
The input begins with an integer \(N\) (\(2 \le N \le 100\)), which indicates the size of the grid. In hack cases or offline testing, the hidden treasure layout will be provided as \(N\) subsequent lines, each containing a string of exactly \(N\) characters ('0' or '1'). A character '0' indicates there is a treasure in that cell, and '1' indicates there is no treasure.
outputFormat
This is an interactive problem. Your program should first, when needed, output queries to the oracle (each query being a line with four integers: \(R_1\), \(C_1\), \(R_2\), \(C_2\)). When you have determined the positions of all treasures, output a line with the word END, followed by \(N\) lines. The \(R\)-th of these lines should be a string of exactly \(N\) characters, where the \(C\)-th character is '0' if the cell at row \(R\) and column \(C\) contains a treasure, and '1' otherwise.
sample
2
01
11
END
01
11
</p>