結果

問題 No.1830 Balanced Majority
ユーザー ikomaikoma
提出日時 2022-02-04 22:40:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 559 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 88,044 KB
平均クエリ数 7.50
最終ジャッジ日時 2023-09-02 05:12:06
合計ジャッジ時間 4,587 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

def request(k):
    print(f"? {k}", flush=True)
    return int(input())*2-k
sign = lambda x:(1 if x>0 else (0 if x==0 else -1))

ans1 = request(1)
ansnm1 = request(N-1)
if ans1==ansnm1:
    print(f"! 1 {N-1}", flush=True)
    exit()


l,r = 1,N
la,ra = ans1,N//2
while l+1<r:
    m = (l+r)//2
    ans = request(m)
    if ans==0:
        break
    if sign(ans)*sign(la) < 0:
        r = m
        ra = ans
    else:
        l = m
        la = ans
if ans <= N//2:
    print(f"! {ans} {N}", flush=True)
else:
    print(f"! {1} {ans}", flush=True)
0