結果

問題 No.1830 Balanced Majority
ユーザー 👑 H20H20
提出日時 2022-02-04 22:22:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,220 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 95,364 KB
平均クエリ数 2.92
最終ジャッジ日時 2023-09-02 05:03:24
合計ジャッジ時間 6,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
readline = sys.stdin.readline
write = sys.stdout.write
flush = sys.stdout.flush


# クエリ: "? x1 x2" を出力
def query(x1):
    write("? %d\n" % (x1))
    flush()
    # ジャッジから返される値を取得
    return readline().strip()

# 回答: "! x" を出力
def answer(x1,x2):
    write("! %d %d\n" % (x1,x2))
    flush()
    # 即時終了
    exit(0)

N = int(input())
if N<=20:
    L = [0]*N
    for i in range(1,N+1):
        l = query(i)
        L[i-1]=l
    for i in range(N):
        for j in range(i+1,N):
            if j-i>=N//2 and (j-i)%2==0 and L[j]-L[i]==(j-i)/2:
                answer(i+1,j+1)

T2 = query(2)
if T2==1:
    answer(3,N)
B2 = query(N-2)
if N-B2==1-N//2:
    answer(1,N-2)
if T2+B2==N//2:
    answer(4,N-2)

#途中だけど!
def is_ok(m):
    m = m-m%4
    if m==0:
        m=4
    v = query(m)
    if v==m//2:
        if m<=N//2:
            answer(m,N)
        else:
            answer(1,m)
    if T2==0:
        return v>m//2
    else:
        return v<m//2

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

meguru_bisect(N,1)
0