問題一覧 > 通常問題

No.850 Company Contest 2nd Place

レベル : / AI推定難易度 : 1575 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / リアクティブ問題 (詳しくはこちら)
タグ : (AC するまで非表示) / 解いたユーザー数 102
作問者 : chocorusk / テスター : omochana2
お気に入りにしたユーザー ProblemId : 2870 / 自分の提出
問題文最終更新日: 2019-07-04 17:01:48
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
yukicoder contest 217 (順位表) の他の問題:

Problem Statement

A programming contest hosted by Yukikoda Inc. was held. $N$ people numbered $1, 2, \ldots , N$ participated in the contest, and everyone received a distinct rank from $1$ st to $N$ th place.

You are a recruiter at Yukikoda Inc. and have decided to scout the person who placed $2$ nd, but since you do not yet know the results of the contest, you have decided to ask the participants questions.

The participants are all contrarians, so they will only answer questions of the following form.

  • Between person $x$ and person $y$ ($x\neq y$), which one ranked higher?

Identify the number of the person who placed $2$ nd by asking at most $334$ questions of this form.

Input and Output

First, the number of participants $N$ ($2\leq N\leq 300$) is given from standard input as follows.

$N$

Then, your program can make up to $334$ question queries by writing to standard output in the following format.

? $x\ y$

This output means asking which of person $x$ and person $y$ ranked higher. $x$ and $y$ must be integers satisfying $1\leq x, y\leq N$, $x\neq y$.

After you make a question query, its answer is given from standard input in the following format.

$ans$

If person $x$ ranked higher (has a smaller rank number), then $ans=x$; otherwise, $ans=y$.

Finally, you must output your answer in the following format.

! $ans$

Your answer is judged correct if the number of the person who placed $2$ nd can be uniquely determined from the question queries made so far and that number equals $ans$.

Notes

  • After each output, you must flush standard output.
  • After each question query, be sure to read its result.
  • After outputting your answer, your program must terminate immediately.
  • In some test cases, the answers to question queries may change depending on the question queries made so far, but an answer will never contradict the question queries made so far.

Sample

Sample 1
Input
4
4
2
1
Output
? 1 4
? 2 4
? 1 3
! 4

This is an example of input and output where there are $4$ participants, and the $1$ st, $2$ nd, $3$ rd, and $4$ th places are fixed as person $2$, person $4$, person $1$, and person $3$, respectively.

  • Between person $1$ and person $4$, the one who ranked higher is person $4$.
  • Between person $2$ and person $4$, the one who ranked higher is person $2$.
  • Between person $1$ and person $3$, the one who ranked higher is person $1$.
  • From the contents of the $3$ question queries, the number of the person who placed $2$ nd is determined to be $4$, so this is judged correct.

Here is an example of incorrect input and output for the same case.

Input
4
1
2
2
Output
? 1 3
? 2 4
? 1 2
! 4

This output correctly answers that the number of the person who placed $2$ nd is $4$, but from the contents of the question queries it cannot be determined whether the number of the person who placed $2$ nd is $1$ or $4$, so this output is judged incorrect.

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