結果

問題 No.1830 Balanced Majority
ユーザー KudeKude
提出日時 2022-02-04 21:44:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 87,780 KB
平均クエリ数 7.54
最終ジャッジ日時 2023-09-02 04:39:34
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
87,452 KB
testcase_01 AC 95 ms
87,116 KB
testcase_02 AC 98 ms
87,456 KB
testcase_03 AC 96 ms
87,368 KB
testcase_04 AC 96 ms
87,164 KB
testcase_05 AC 95 ms
87,288 KB
testcase_06 AC 95 ms
87,228 KB
testcase_07 AC 97 ms
87,032 KB
testcase_08 AC 98 ms
87,204 KB
testcase_09 AC 98 ms
87,152 KB
testcase_10 AC 97 ms
87,028 KB
testcase_11 AC 98 ms
87,472 KB
testcase_12 AC 95 ms
86,920 KB
testcase_13 AC 99 ms
86,812 KB
testcase_14 AC 103 ms
87,116 KB
testcase_15 AC 100 ms
87,036 KB
testcase_16 AC 99 ms
86,948 KB
testcase_17 AC 97 ms
87,112 KB
testcase_18 AC 95 ms
87,264 KB
testcase_19 AC 96 ms
87,260 KB
testcase_20 AC 94 ms
87,460 KB
testcase_21 AC 98 ms
87,376 KB
testcase_22 AC 97 ms
86,888 KB
testcase_23 AC 100 ms
87,780 KB
testcase_24 AC 98 ms
87,004 KB
testcase_25 AC 96 ms
87,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
def ask(x):
    print(f'? {x}')
    r = int(input())
    return r - (x - r)
def answer(l, r):
    print(f'! {l + 1} {r}')
    exit(0)

res0, res1 = ask(1), ask(n - 1)
if res0 == res1:
    answer(1, n - 1)

l, r = 1, n - 1  # (l, r)
while True:
    c = (l + r) // 2
    res = ask(c)
    if res == 0:
        if c <= n // 2:
            answer(c, n)
        else:
            answer(0, c)
    if res > 0 and res0 > 0 or res < 0 and res0 < 0:
        l = c
    else:
        r = c
0