結果

問題 No.594 壊れた宝物発見機
ユーザー maspymaspy
提出日時 2020-02-29 20:11:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,749 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 25,060 KB
平均クエリ数 44.70
最終ジャッジ日時 2023-09-23 20:40:39
合計ジャッジ時間 4,102 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
24,940 KB
testcase_01 AC 129 ms
24,500 KB
testcase_02 AC 127 ms
24,896 KB
testcase_03 AC 128 ms
24,840 KB
testcase_04 AC 128 ms
24,316 KB
testcase_05 AC 130 ms
24,504 KB
testcase_06 AC 128 ms
25,036 KB
testcase_07 AC 129 ms
24,456 KB
testcase_08 AC 130 ms
24,412 KB
testcase_09 AC 128 ms
24,784 KB
testcase_10 AC 131 ms
24,428 KB
testcase_11 AC 128 ms
25,060 KB
testcase_12 AC 130 ms
24,328 KB
testcase_13 AC 131 ms
24,304 KB
testcase_14 AC 131 ms
24,428 KB
testcase_15 AC 130 ms
24,972 KB
testcase_16 AC 131 ms
24,476 KB
testcase_17 AC 129 ms
24,676 KB
testcase_18 AC 130 ms
24,600 KB
testcase_19 AC 128 ms
24,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
readline = sys.stdin.readline
from functools import lru_cache

# %%
# DEBUG = True
DEBUG = False

# %%


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

    def create_data(self):
        import random
        x, y, z = [random.randint(-150, 151) for _ in range(3)]
        print('created', x, y, z)
        self.x = x
        self.y = y
        self.z = z

    def resp_ques(self, *args):
        x, y, z = args
        d = (self.x - x) ** 2 + (self.y - y) ** 2 + (self.z - z) ** 2
        return f'{d}\n'

    def resp_ans(self, *args):
        x, y, z = args
        if x == self.x and y == self.y and z == self.z:
            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 find_kth_coord(k):
    @lru_cache(None)
    def f(x):
        values = [0, 0, 0]
        values[k] = x
        resp = int(question(*values))
        return resp
    left = -151
    right = 150
    while left + 1 < right:
        x = (left + right) // 2
        if f(x) < f(x + 1):
            right = x
        else:
            left = x
    return right


# %%
x, y, z = [find_kth_coord(k) for k in [0, 1, 2]]
answer(x, y, z)
0