結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-22 16:55:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 2,000 ms |
| コード長 | 995 bytes |
| コンパイル時間 | 253 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 78,808 KB |
| 平均クエリ数 | 200.04 |
| 最終ジャッジ日時 | 2024-09-20 12:43:45 |
| 合計ジャッジ時間 | 4,620 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
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()