結果

問題 No.1830 Balanced Majority
ユーザー 👑 KazunKazun
提出日時 2022-02-05 10:01:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 89,220 KB
平均クエリ数 8.27
最終ジャッジ日時 2023-09-02 06:28:40
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
86,884 KB
testcase_01 AC 93 ms
87,420 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 95 ms
87,644 KB
testcase_05 AC 92 ms
87,392 KB
testcase_06 AC 92 ms
87,776 KB
testcase_07 AC 97 ms
89,048 KB
testcase_08 AC 101 ms
89,072 KB
testcase_09 AC 98 ms
89,220 KB
testcase_10 AC 99 ms
88,980 KB
testcase_11 AC 99 ms
88,832 KB
testcase_12 AC 99 ms
88,820 KB
testcase_13 AC 99 ms
89,044 KB
testcase_14 AC 103 ms
89,164 KB
testcase_15 AC 98 ms
88,884 KB
testcase_16 AC 97 ms
89,120 KB
testcase_17 AC 98 ms
88,752 KB
testcase_18 AC 93 ms
87,916 KB
testcase_19 AC 93 ms
87,688 KB
testcase_20 AC 93 ms
87,364 KB
testcase_21 AC 101 ms
88,864 KB
testcase_22 AC 100 ms
88,744 KB
testcase_23 AC 101 ms
88,652 KB
testcase_24 AC 99 ms
88,424 KB
testcase_25 AC 93 ms
87,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def question(K):
    print("?",K,flush=True)
    S=int(input())
    T[K]=S-(K-S)

def answer(L,R):
    print("!",L,R,flush=True)
    exit()

def General_Binary_Increase_Search_Integer(L,R,cond,default=None):
    """条件式が単調増加であるとき, 整数上で二部探索を行う.
    L: 解の下限
    R: 解の上限
    cond: 条件(1変数関数, 広義単調増加を満たす)
    default: Lで条件を満たさないときの返り値
    """
    #if not(cond(R)): return default

    #if cond(L): return L

    R+=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C): R=C
        else: L=C
    return R

def check(x):
    question(x)
    return T[x]*T[N-1]>=0
#==================================================
N=int(input())
T=[None]*(N+1)

question(1); question(N-1)

if T[1]==T[N-1]:
    answer(2,N-1)

M=General_Binary_Increase_Search_Integer(2,N-1,check)

if N//2<=M:
    answer(1,M)
else:
    answer(M+1,N)
0