結果

問題 No.850 企業コンテスト2位
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-05-22 16:55:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 79,808 KB
平均クエリ数 200.04
最終ジャッジ日時 2023-10-20 17:08:55
合計ジャッジ時間 5,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
69,860 KB
testcase_01 AC 56 ms
69,860 KB
testcase_02 AC 55 ms
69,860 KB
testcase_03 AC 56 ms
69,860 KB
testcase_04 AC 57 ms
69,860 KB
testcase_05 AC 57 ms
69,860 KB
testcase_06 AC 57 ms
69,860 KB
testcase_07 AC 63 ms
69,860 KB
testcase_08 AC 68 ms
75,508 KB
testcase_09 AC 71 ms
75,508 KB
testcase_10 AC 81 ms
77,752 KB
testcase_11 AC 79 ms
77,752 KB
testcase_12 AC 77 ms
77,752 KB
testcase_13 AC 78 ms
77,752 KB
testcase_14 AC 77 ms
77,752 KB
testcase_15 AC 78 ms
77,752 KB
testcase_16 AC 77 ms
77,752 KB
testcase_17 AC 81 ms
77,752 KB
testcase_18 AC 76 ms
77,752 KB
testcase_19 AC 78 ms
77,752 KB
testcase_20 AC 79 ms
77,752 KB
testcase_21 AC 80 ms
79,808 KB
testcase_22 AC 79 ms
77,752 KB
testcase_23 AC 80 ms
77,752 KB
testcase_24 AC 78 ms
77,752 KB
testcase_25 AC 79 ms
77,752 KB
testcase_26 AC 83 ms
77,752 KB
testcase_27 AC 54 ms
69,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

n = int(input())
battle = [[-1]*n for i in range(n)]

lose = [0]*n
b = len(bin(n))-3

dif = n%(1<<b)

def update(x,y):
    win = int(input())-1
    if win == x:
        battle[x][y] = 1
        battle[y][x] = 0
        lose[y] = 1
    else:
        battle[y][x] = 1
        battle[x][y] = 0
        lose[x] = 1
for i in range(dif):
    x,y = 2*i,2*i+1
    print("?",x+1,y+1)
    sys.stdout.flush()
    update(x,y)

    

for i in range(b-1,-1,-1):

    left = [i for i in range(n) if lose[i] == 0]

    l = 1<<i
    for j in range(l):
        x,y = left[2*j],left[2*j+1]
        print("?",x+1,y+1)
        sys.stdout.flush()
        update(x,y)

left = [i for i in range(n) if lose[i] == 0]
win = left[0]

cand = []

for i in range(n):
    if battle[win][i] == 1:
        cand.append(i)

second = cand[0]
for i in cand[1:]:
    print("?",second+1,i+1)
    sys.stdout.flush()
    win = int(input())-1
    if second != win:
        second = i
print("!",second+1)
sys.stdout.flush()



0