結果

問題 No.253 ロウソクの長さ
ユーザー maspymaspy
提出日時 2020-03-04 11:49:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,840 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 24,592 KB
平均クエリ数 29.47
最終ジャッジ日時 2023-09-24 02:31:39
合計ジャッジ時間 4,087 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
24,080 KB
testcase_01 AC 40 ms
24,532 KB
testcase_02 AC 39 ms
24,572 KB
testcase_03 AC 40 ms
24,496 KB
testcase_04 AC 40 ms
24,168 KB
testcase_05 AC 44 ms
24,012 KB
testcase_06 AC 41 ms
24,116 KB
testcase_07 AC 40 ms
24,244 KB
testcase_08 AC 41 ms
24,028 KB
testcase_09 AC 40 ms
24,212 KB
testcase_10 AC 40 ms
23,924 KB
testcase_11 AC 40 ms
24,528 KB
testcase_12 AC 41 ms
24,296 KB
testcase_13 AC 41 ms
24,476 KB
testcase_14 AC 41 ms
24,488 KB
testcase_15 AC 41 ms
24,168 KB
testcase_16 AC 40 ms
24,080 KB
testcase_17 AC 41 ms
24,416 KB
testcase_18 AC 41 ms
24,276 KB
testcase_19 AC 41 ms
24,400 KB
testcase_20 AC 41 ms
24,388 KB
testcase_21 AC 43 ms
24,140 KB
testcase_22 AC 41 ms
24,364 KB
testcase_23 AC 41 ms
24,540 KB
testcase_24 AC 42 ms
24,216 KB
testcase_25 AC 41 ms
24,104 KB
testcase_26 AC 40 ms
24,100 KB
testcase_27 AC 41 ms
24,344 KB
testcase_28 AC 41 ms
23,884 KB
testcase_29 AC 41 ms
24,216 KB
testcase_30 AC 42 ms
24,016 KB
testcase_31 AC 41 ms
24,076 KB
testcase_32 AC 41 ms
24,592 KB
testcase_33 AC 40 ms
24,116 KB
testcase_34 AC 41 ms
24,268 KB
testcase_35 AC 40 ms
24,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
readline = sys.stdin.readline
# %%
DEBUG = True
DEBUG = False


# %%
class Interactive:
    def __init__(self):
        self.ques_cnt = 0
        self.create_data()

    def create_data(self):
        import random
        self.ans = random.randint(10, 10 ** 9)
        self.x = self.ans + 1
        print('created', self.x)

    def resp_ques(self, *args):
        self.x -= 1
        if self.x < 0:
            self.x = 0
        x = int(args[0])
        if x < self.x:
            return '1\n'
        elif x == self.x:
            return '0\n'
        else:
            return '-1\n'

    def resp_ans(self, *args):
        x = int(args[0])
        if x == self.ans:
            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()


# %%
def first_strategy():
    resp = int(question(80))
    if resp == 0:
        answer(80)
    if resp == 1:
        return
    k = 1
    while True:
        resp = int(question(5))
        if resp == 0:
            answer(5 + k)
        k += 1


# %%
first_strategy()
k = 0
left = 1
right = 10 ** 9 + 1
while left + 1 < right:
    k += 1
    x = (left + right) // 2
    resp = int(question(x - k))
    if resp == 0:
        answer(x)
        break
    if resp == -1:
        right = x
    if resp == 1:
        left = x
0