結果

問題 No.850 企業コンテスト2位
ユーザー Shirotsume
提出日時 2023-11-28 23:55:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 79,192 KB
平均クエリ数 200.11
最終ジャッジ日時 2024-09-26 13:12:13
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

def query(x, y):
    print('?', x + 1, y + 1, flush=True)
    return ii() - 1
def answer(x):
    print('!', x + 1, flush=True)

n = ii()
beat = [inf] * n
now = list(range(n))

while len(now) > 1:
    now2 = []
    for i in range(0, len(now) - 1, 2):
        x = now[i]
        y = now[i + 1]
        z = query(x, y)
        if z == x:
            beat[y] = x
            now2.append(x)
        else:
            beat[x] = y
            now2.append(y)
    if len(now) % 2:
        now2.append(now[-1])
    now = now2

V = [v for v in range(n) if beat[v] == now[0]]

ans = V[0]

for i in range(1, len(V)):
    if query(ans, V[i]) == V[i]:
        ans = V[i]

answer(ans)
    

        
        
0