結果
問題 | No.1830 Balanced Majority |
ユーザー |
![]() |
提出日時 | 2022-02-05 00:35:25 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,133 bytes |
コンパイル時間 | 221 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 69,600 KB |
平均クエリ数 | 7.77 |
最終ジャッジ日時 | 2024-06-11 13:14:30 |
合計ジャッジ時間 | 3,231 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 21 WA * 4 |
ソースコード
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,2): if N-1>j-i+1>=N/2 and L[j]-L[i]==(j-i+1)/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==2 and B2==N/2) or (T2==0 and B2==N/2-2) : answer(3,N-2) def is_ok(m): v = query(m) if v==m/2: if m<N/2: answer(m+1,N) else: answer(1,m) 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,2)