結果

問題 No.1830 Balanced Majority
コンテスト
ユーザー titia
提出日時 2022-02-06 00:47:25
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 779 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 722 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 34,448 KB
平均クエリ数 7.42
最終ジャッジ日時 2026-03-04 14:55:06
合計ジャッジ時間 4,842 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

N=int(input())

print("?",1,flush=True)
x=int(input())
init=x
print("?",N-1,flush=True)
y=int(input())

if x==1 and y==N//2:
    print("!",2,N-1,flush=True)
    exit()
elif x==0 and y==N//2-1:
    print("!",2,N-1,flush=True)
    exit()

# 1~xの表 - 裏の枚数が0になるものを探す

MIN=2
MAX=N-1

while True:
    mid=(MIN+MAX)//2

    print("?",mid,flush=True)
    x=int(input())
    y=mid-x

    if init==1:
        if x<y:
            MAX=mid
        elif x>y:
            MIN=mid
        else:
            break
    else:
        if x>y:
            MAX=mid
        elif x<y:
            MIN=mid
        else:
            break
        

if mid>=N//2:
    print("!",1,mid,flush=True)
else:
    print("!",mid+1,N,flush=True)
0