結果

問題 No.850 企業コンテスト2位
ユーザー chineristACchineristAC
提出日時 2020-10-19 18:34:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 80,108 KB
平均クエリ数 200.11
最終ジャッジ日時 2024-07-17 07:11:20
合計ジャッジ時間 4,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def query(x,y):
    print("?",x,y)
    sys.stdout.flush()
    return int(input())

from collections import deque

N = int(input())
deq = deque([i for i in range(1,N+1)])

win = [[] for  i in range(N+1)]

while len(deq)>1:
    ndeq = deque([])
    while deq:
        x = deq.popleft()
        if not deq:
            ndeq.append(x)
            break
        y = deq.popleft()
        z = query(x,y)
        if z==x:
            win[x].append(y)
        else:
            win[y].append(x)
        ndeq.append(z)
    deq = ndeq

one = deq[0]

L = win[one]
res = L[0]
for i in range(1,len(L)):
    res = query(res,L[i])

print("!",res)
0