結果

問題 No.1830 Balanced Majority
ユーザー 👑 H20H20
提出日時 2022-02-04 22:38:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,716 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 88,072 KB
平均クエリ数 5.73
最終ジャッジ日時 2023-09-02 05:10:58
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 95 ms
87,276 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 97 ms
87,284 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 96 ms
87,440 KB
testcase_15 AC 96 ms
87,572 KB
testcase_16 AC 98 ms
87,620 KB
testcase_17 AC 99 ms
86,964 KB
testcase_18 AC 95 ms
87,648 KB
testcase_19 AC 96 ms
87,412 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 95 ms
87,208 KB
権限があれば一括ダウンロードができます

ソースコード

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 int(readline())

# 回答: "! 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 B2==N//2-1:
    answer(1,N-2)
if T2+B2==N//2:
    answer(3,N-2)

#途中だけど!
def is_ok(m):
    m = m-m%2
    if m==0:
        m=2
    v = query(m)
    if v==m/2:
        if m<=N/2:
            answer(m,N)
        else:
            answer(1,m)
    if T2==0:
        if v+1==m/2:
            if m>N/2:
                answer(2,m)
            else:
                answer(m,N-1)
        if v+2==m/2:
            if m>N/2:
                answer(3,m)
            else:
                answer(m,N-2)
    else:
        if v-1==m/2:
            if m>N/2:
                answer(2,m)
            else:
                answer(m,N-1)
        if v-2==m/2:
            if m>N/2:
                answer(3,m)
            else:
                answer(m,N-2)
    
    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