結果

問題 No.1830 Balanced Majority
コンテスト
ユーザー Kude
提出日時 2022-02-04 21:44:30
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 495 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 115 ms
コンパイル使用メモリ 85,564 KB
実行使用メモリ 72,688 KB
平均クエリ数 7.54
最終ジャッジ日時 2026-03-04 12:56:18
合計ジャッジ時間 2,544 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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