問題一覧 > 通常問題

No.3737 Quiz Time

レベル : / AI推定難易度 : 1800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / リアクティブ問題 (詳しくはこちら)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 21
作問者 : 👑 kencho / テスター : uruzunyaa
お気に入りにしたユーザー ProblemId : 13628 / 自分の提出
問題文最終更新日: 2026-11-02 04:28:53
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
グリッド構築24題 (順位表) の他の問題:

Problem Statement

This is an interactive problem.

You are going to play a game with Kencho.

The game is as follows.

  • Kencho secretly holds his favorite $P \times P$ grid $A$. Each cell of $A$ contains exactly $1$ integer, and each integer between $1$ and $P^2$, inclusive, is written in exactly $1$ cell. Hereafter, let $A_{i, j}$ denote the integer written in the cell at the $i$-th row from the top and the $j$-th column from the left of $A$.
  • You can ask the following question up to $P$ times.
    • Specify a pair of integers $(i, j)$ satisfying $1 \leq i, j \leq P$. Kencho answers with $A_{i, j}$.
  • After the questions, you win if you can correctly state the integers written in all cells of the grid $A$; otherwise, Kencho wins.

Thinking that your chances of winning are slim as things stand, you hired a skilled spy and obtained the following top-secret information.

  • $A_{i, j} + A_{i+1, j+1} = A_{i, j+1} + A_{i+1, j}\ (1 \leq i, j \leq P-1)$ holds.

Win the game. You may assume that the information provided by the spy is correct.

Constraints

  • All input values are integers.
  • $2 \leq P \leq 97$
  • $P$ is a prime number.

Input and Output

First, $P$ is given from standard input.

$P$

You can then ask questions. Print each question to standard output in the following format.

? $i$ $j$

The response to a question is given from standard input in the following format.

$A_{i,j}$

However, if the format or constraints of a question are violated, or if the number of questions exceeds $P$, -1 is given from standard input instead. In this case, terminate your program immediately.

To state the integers in all cells of $A$, print them to standard output in the following format.

!
$A_{1, 1}\ A_{1, 2}\ \ldots\ A_{1, P}$
$A_{2, 1}\ A_{2, 2}\ \ldots\ A_{2, P}$
$\vdots$
$A_{P, 1}\ A_{P, 2}\ \ldots\ A_{P, P}$

After that, terminate your program immediately.

End each output with a newline and flush standard output.

Notes

  • You must flush standard output after each output.
  • After asking a question, you must always receive its response.
  • After printing the determined $A$, you must terminate your program immediately.
  • $A$ is fixed in advance for each test case and does not change during the interaction depending on your questions.

Sample Interaction

In this case, $A_{1, 1} = 2, A_{1, 2} = 4, A_{2, 1} = 1, A_{2, 2} = 3$.

InputOutputExplanation
2$P = 2$ is given.
? 1 2Ask a question choosing $(i, j) = (1, 2)$.
4$A_{1, 2} = 4$ is returned as the response.
? 2 1Ask a question choosing $(i, j) = (2, 1)$.
1$A_{2, 1} = 1$ is returned as the response.
!
2 4
1 3
Answer with $A_{1, 1} = 2, A_{1, 2} = 4, A_{2, 1} = 1, A_{2, 2} = 3$.
The responses to the questions above alone do not uniquely determine $A$, but in this example the printed grid matches the actual $A$, so it is judged correct.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。