結果

問題 No.850 企業コンテスト2位
ユーザー ShirotsumeShirotsume
提出日時 2023-11-28 23:55:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 79,876 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-11-28 23:55:34
合計ジャッジ時間 5,219 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
72,272 KB
testcase_01 AC 62 ms
72,272 KB
testcase_02 AC 62 ms
72,272 KB
testcase_03 AC 62 ms
72,272 KB
testcase_04 AC 62 ms
72,272 KB
testcase_05 AC 61 ms
72,272 KB
testcase_06 AC 61 ms
72,272 KB
testcase_07 AC 68 ms
72,272 KB
testcase_08 AC 72 ms
74,332 KB
testcase_09 AC 71 ms
74,332 KB
testcase_10 AC 108 ms
79,876 KB
testcase_11 AC 85 ms
79,876 KB
testcase_12 AC 84 ms
79,876 KB
testcase_13 AC 82 ms
79,876 KB
testcase_14 AC 84 ms
79,876 KB
testcase_15 AC 80 ms
79,868 KB
testcase_16 AC 80 ms
79,872 KB
testcase_17 AC 82 ms
79,876 KB
testcase_18 AC 81 ms
79,876 KB
testcase_19 AC 81 ms
79,876 KB
testcase_20 AC 90 ms
79,876 KB
testcase_21 AC 91 ms
79,876 KB
testcase_22 AC 82 ms
79,876 KB
testcase_23 AC 82 ms
79,876 KB
testcase_24 AC 82 ms
79,876 KB
testcase_25 AC 82 ms
79,876 KB
testcase_26 AC 82 ms
79,876 KB
testcase_27 AC 62 ms
72,280 KB
権限があれば一括ダウンロードができます

ソースコード

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