結果

問題 No.1830 Balanced Majority
ユーザー Kude
提出日時 2022-02-04 21:44:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 69,344 KB
平均クエリ数 7.54
最終ジャッジ日時 2024-06-11 11:39:09
合計ジャッジ時間 3,086 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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