結果

問題 No.1830 Balanced Majority
ユーザー 👑 H20H20
提出日時 2022-02-05 01:27:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 87,664 KB
平均クエリ数 7.88
最終ジャッジ日時 2023-09-02 06:21:30
合計ジャッジ時間 4,488 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
87,404 KB
testcase_01 AC 94 ms
87,116 KB
testcase_02 AC 94 ms
86,756 KB
testcase_03 AC 94 ms
87,040 KB
testcase_04 AC 95 ms
87,416 KB
testcase_05 AC 95 ms
87,044 KB
testcase_06 AC 94 ms
86,896 KB
testcase_07 AC 97 ms
87,068 KB
testcase_08 AC 97 ms
86,944 KB
testcase_09 AC 96 ms
87,260 KB
testcase_10 AC 95 ms
87,108 KB
testcase_11 AC 98 ms
86,876 KB
testcase_12 AC 97 ms
87,224 KB
testcase_13 AC 97 ms
87,564 KB
testcase_14 AC 99 ms
87,244 KB
testcase_15 AC 97 ms
87,420 KB
testcase_16 AC 97 ms
87,104 KB
testcase_17 AC 97 ms
87,288 KB
testcase_18 AC 96 ms
87,104 KB
testcase_19 AC 95 ms
87,304 KB
testcase_20 AC 95 ms
87,292 KB
testcase_21 AC 99 ms
87,212 KB
testcase_22 AC 97 ms
87,044 KB
testcase_23 AC 98 ms
87,224 KB
testcase_24 AC 98 ms
87,068 KB
testcase_25 AC 95 ms
87,664 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+1)
    for i in range(1,N+1):
        l = query(i)
        L[i]=l
    LL = [0]*N
    for i in range(N):
        if L[i+1]!=L[i]:
            LL[i]=1
    for i in range(N):
        for j in range(i+1,N,2):
            if N>j-i+1>=N/2:
                temp = 0
                for k in range(i,j+1):
                    temp+=LL[k]
                if temp*2==j-i+1:
                    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==2 and B2==N/2) or (T2==0 and B2==N/2-2) :
    answer(3,N-2)

def is_ok(m):
    v = query(m)*2-m
    if v==0:
        if m<N/2:
            answer(m+1,N)
        else:
            answer(1,m)
    if T2==0:
        return v<0
    else:
        return v>0

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,2)
0