#P9269. [CEOI 2013] 新宝岛 / Treasure

    ID: 10380 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2013交互题Special JudgeCEOI(中欧)前缀和

[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 NN by NN grid, with both rows and columns numbered from 11 to NN. 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 SS cells, then the Oracle will use 1+N×NS1 + N \times N - S 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 NN (2N1002 \leq N \leq 100), the size of the grid.
  • To ask the Oracle, your program should output one line containing 44 integers R1R_1, C1C_1, R2R_2, and C2C_2, separated by spaces, such that 1R1R2N1 \leq R_1 \leq R_2 \leq N and 1C1C2N1 \leq C_1 \leq C_2 \leq N. If these conditions do not hold, or the line format is incorrect, your program will receive 00 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 (R,C)(R, C) such that R1RR2R_1 \leq R \leq R_2 and C1CC2C_1 \leq C \leq C_2, and the cell in row RR and column CC contains a treasure.
  • When the program finishes asking questions (i.e., it has determined the positions of all treasures), it should output END on a new line. Then output NN lines, each a string of NN characters 0 or 1. The CC-th character of line RR is 1 if the cell in row RR and column CC contains a treasure, and 0 otherwise. Rows are numbered from top to bottom as 11 to NN, 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 NN.

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

Sample explanation

Each test case is worth 1010 points. If your program’s output is incorrect, it gets 00 points for that test case. Otherwise, the score is determined by the total number of energy units used by the Oracle, denoted by KK.

Specifically:

  • If K716N4+N2K \leq \frac{7}{16} N^4 + N^2, you get 1010 points.
  • Otherwise, if K716N4+2N3K \leq \frac{7}{16} N^4 + 2N^3, you get 88 points.
  • Otherwise, if K34N4K \leq \frac{3}{4} N^4, you get 44 points.
  • Otherwise, if KN4K \leq N^4, you get 11 point.
  • Otherwise, you get 00 points.

Also, in testdata that accounts for at least 40%40\% of the total score, NN will be at most 2020.

In summary, the less energy you spend, the higher your score will be.

Interactive library / SPJ provider:

https://www.luogu.com.cn/user/764746

Translated by ChatGPT 5