結果

問題 No.1152 10億ゲーム
ユーザー keijakkeijak
提出日時 2021-04-30 18:44:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,396 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 24,628 KB
平均クエリ数 25.06
最終ジャッジ日時 2023-09-24 10:30:14
合計ジャッジ時間 7,223 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
24,464 KB
testcase_01 AC 81 ms
24,564 KB
testcase_02 AC 83 ms
24,512 KB
testcase_03 AC 83 ms
24,068 KB
testcase_04 AC 82 ms
24,152 KB
testcase_05 AC 84 ms
23,952 KB
testcase_06 AC 83 ms
24,344 KB
testcase_07 AC 84 ms
24,236 KB
testcase_08 AC 82 ms
23,816 KB
testcase_09 AC 81 ms
23,996 KB
testcase_10 AC 83 ms
24,208 KB
testcase_11 AC 83 ms
24,264 KB
testcase_12 AC 83 ms
24,188 KB
testcase_13 AC 84 ms
24,000 KB
testcase_14 AC 85 ms
24,576 KB
testcase_15 AC 84 ms
24,432 KB
testcase_16 AC 82 ms
23,984 KB
testcase_17 AC 84 ms
24,220 KB
testcase_18 AC 83 ms
24,028 KB
testcase_19 AC 84 ms
23,944 KB
testcase_20 AC 84 ms
24,456 KB
testcase_21 AC 84 ms
23,984 KB
testcase_22 AC 83 ms
23,860 KB
testcase_23 AC 84 ms
24,460 KB
testcase_24 AC 82 ms
24,020 KB
testcase_25 AC 83 ms
24,124 KB
testcase_26 AC 84 ms
24,024 KB
testcase_27 AC 83 ms
24,024 KB
testcase_28 AC 84 ms
24,080 KB
testcase_29 AC 84 ms
24,180 KB
testcase_30 AC 83 ms
24,180 KB
testcase_31 AC 84 ms
24,132 KB
testcase_32 AC 83 ms
24,236 KB
testcase_33 AC 83 ms
24,252 KB
testcase_34 AC 84 ms
24,268 KB
testcase_35 AC 83 ms
24,040 KB
testcase_36 AC 84 ms
24,152 KB
testcase_37 AC 84 ms
24,032 KB
testcase_38 AC 81 ms
24,216 KB
testcase_39 AC 82 ms
23,876 KB
testcase_40 AC 81 ms
24,624 KB
testcase_41 AC 82 ms
24,432 KB
testcase_42 AC 82 ms
24,628 KB
testcase_43 AC 82 ms
24,268 KB
testcase_44 AC 82 ms
24,344 KB
testcase_45 AC 82 ms
24,216 KB
testcase_46 AC 82 ms
24,484 KB
testcase_47 AC 81 ms
24,488 KB
testcase_48 AC 79 ms
24,096 KB
testcase_49 AC 79 ms
24,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def decode(x):
    c2, c5 = 0, 0
    while x % 2 == 0:
        c2 += 1
        x //= 2
    while x % 5 == 0:
        c5 += 1
        x //= 5
    assert x == 1
    return [c2, c5]


def encode(p):
    c2, c5 = p
    x = 1
    for i in range(c2):
        x *= 2
    for i in range(c5):
        x *= 5
    return x


def solve():
    x1, x2 = [int(x) for x in input().split()]
    p1 = decode(x1)
    p2 = decode(x2)

    def query():
        nonlocal x1, x2, p1, p2
        x1 = encode(p1)
        print(x1, flush=True)
        if x1 == x2:
            exit(0)
        x2 = int(input())
        if x1 == x2:
            exit(0)
        p2 = decode(x2)

    P = 2 ** 7 * 5 ** 9
    while x1 != P:
        if p1[0] > 7:
            p1[0] -= 1
        elif p1[0] < 7:
            p1[0] += 1
        elif p1[1] < 9:
            p1[1] += 1
        else:
            assert False
        query()

    if x2 > x1:
        print(x2, flush=True)
        exit(0)

    if (p1[0] + p1[1]) % 2 == (p2[0] + p2[1]) % 2:
        p1[0] += 2
        query()

    while True:
        d2 = abs(p1[0] - p2[0])
        d5 = abs(p1[1] - p2[1])
        if d2 < d5:
            if p1[1] > p2[1]:
                p1[1] -= 1
            else:
                p1[1] += 1
        else:
            if p1[0] > p2[0]:
                p1[0] -= 1
            else:
                p1[0] += 1
        query()


solve()
0