結果

問題 No.850 企業コンテスト2位
ユーザー maspymaspy
提出日時 2020-03-31 12:14:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,799 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 24,672 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-24 03:15:06
合計ジャッジ時間 3,557 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
24,396 KB
testcase_01 AC 39 ms
24,252 KB
testcase_02 AC 39 ms
24,576 KB
testcase_03 AC 39 ms
24,268 KB
testcase_04 AC 39 ms
24,440 KB
testcase_05 AC 39 ms
24,112 KB
testcase_06 AC 38 ms
24,292 KB
testcase_07 AC 45 ms
24,452 KB
testcase_08 AC 46 ms
24,072 KB
testcase_09 AC 46 ms
23,944 KB
testcase_10 AC 52 ms
24,068 KB
testcase_11 AC 51 ms
24,392 KB
testcase_12 AC 51 ms
24,624 KB
testcase_13 AC 50 ms
24,068 KB
testcase_14 AC 51 ms
24,060 KB
testcase_15 AC 50 ms
24,572 KB
testcase_16 AC 49 ms
24,140 KB
testcase_17 AC 52 ms
24,236 KB
testcase_18 AC 51 ms
24,452 KB
testcase_19 AC 50 ms
24,540 KB
testcase_20 AC 51 ms
24,364 KB
testcase_21 AC 52 ms
24,444 KB
testcase_22 AC 52 ms
23,992 KB
testcase_23 AC 51 ms
23,896 KB
testcase_24 AC 52 ms
24,272 KB
testcase_25 AC 51 ms
24,672 KB
testcase_26 AC 51 ms
24,112 KB
testcase_27 AC 39 ms
24,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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])
0