結果

問題 No.1830 Balanced Majority
ユーザー ikomaikoma
提出日時 2022-02-04 23:12:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 87,544 KB
平均クエリ数 7.54
最終ジャッジ日時 2023-09-02 05:49:08
合計ジャッジ時間 4,563 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
86,632 KB
testcase_01 AC 95 ms
87,428 KB
testcase_02 AC 94 ms
86,796 KB
testcase_03 AC 95 ms
87,204 KB
testcase_04 AC 92 ms
87,168 KB
testcase_05 AC 95 ms
87,428 KB
testcase_06 AC 97 ms
87,356 KB
testcase_07 AC 97 ms
87,000 KB
testcase_08 AC 98 ms
87,268 KB
testcase_09 AC 99 ms
86,964 KB
testcase_10 AC 97 ms
87,036 KB
testcase_11 AC 97 ms
87,412 KB
testcase_12 AC 99 ms
87,304 KB
testcase_13 AC 102 ms
87,004 KB
testcase_14 AC 100 ms
87,456 KB
testcase_15 AC 98 ms
87,524 KB
testcase_16 AC 98 ms
87,344 KB
testcase_17 AC 98 ms
87,208 KB
testcase_18 AC 99 ms
87,472 KB
testcase_19 AC 99 ms
87,232 KB
testcase_20 AC 96 ms
87,524 KB
testcase_21 AC 97 ms
87,512 KB
testcase_22 AC 99 ms
87,060 KB
testcase_23 AC 97 ms
87,544 KB
testcase_24 AC 98 ms
87,428 KB
testcase_25 AC 96 ms
87,404 KB
権限があれば一括ダウンロードができます

ソースコード

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"! 2 {N-1}", flush=True)
    exit()


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