結果
| 問題 |
No.1830 Balanced Majority
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2022-02-04 21:28:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 829 bytes |
| コンパイル時間 | 2,070 ms |
| コンパイル使用メモリ | 193,340 KB |
| 最終ジャッジ日時 | 2025-01-27 18:40:51 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
cout << "? " << 1 << endl;
int S1;
cin >> S1;
cout << "? " << N - 1 << endl;
int S2;
cin >> S2;
S1 -= 1 - S1;
S2 -= N - 1 - S2;
if (S1 == S2){
cout << "! " << 2 << ' ' << N - 1 << endl;
} else {
int tv = 1, fv = N - 1;
int p = -1;
while (fv - tv > 1){
int mid = (tv + fv) / 2;
cout << "? " << mid << endl;
int S;
cin >> S;
S -= mid - S;
if (S == 0){
p = mid;
break;
} else if (S1 > 0 && S > 0 || S1 < 0 && S < 0){
tv = mid;
} else {
fv = mid;
}
}
if (p == -1){
p = tv;
}
if (p >= N / 2){
cout << "! " << 1 << ' ' << p << endl;
} else {
cout << "! " << p + 1 << ' ' << N << endl;
}
}
}
SSRS