結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-31 12:14:16 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 2,000 ms |
| コード長 | 1,799 bytes |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 27,864 KB |
| 平均クエリ数 | 200.11 |
| 最終ジャッジ日時 | 2024-07-17 03:22:43 |
| 合計ジャッジ時間 | 3,931 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#!/usr/bin/ python3.8
import sys
readline = sys.stdin.readline
# DEBUG = True
DEBUG = False
N = int(readline())
class Interactive:
def __init__(self):
self.ques_cnt = 0
self.create_data()
def create_data(self):
import numpy as np
rank = np.arange(N + 1)
np.random.shuffle(rank[1:])
self.rank = rank
print('created', rank)
def resp_ques(self, *args):
x, y = args
ret = x if self.rank[x] < self.rank[y] else y
return str(ret) + '\n'
def resp_ans(self, *args):
x = args
if self.rank[x] == 2:
print('AC')
else:
print('WA')
if DEBUG:
interactive = Interactive()
def question(*args, offset='?'):
if offset is None:
print(*args, flush=True)
else:
print(offset, *args, flush=True)
if DEBUG:
resp = interactive.resp_ques(*args)
print(resp, end='')
return resp
else:
return readline()
def answer(*args, offset='!'):
if offset is None:
print(*args, flush=True)
else:
print(offset, *args, flush=True)
if DEBUG:
interactive.resp_ans(*args)
else:
exit()
log = []
A = list(range(1, N + 1))
while len(A) >= 2:
B = []
it = iter(A)
for x, y in zip(it, it):
ret = int(question(x, y))
log.append((x, y, ret))
B.append(ret)
if len(A) % 2 == 1:
B.append(A[-1])
A = B
best_x = A[0]
A = []
for x, y, z in log:
if z == best_x:
A.append(x + y - z)
while len(A) >= 2:
B = []
it = iter(A)
for x, y in zip(it, it):
ret = int(question(x, y))
log.append((x, y, ret))
B.append(ret)
if len(A) % 2 == 1:
B.append(A[-1])
A = B
answer(A[0])
maspy