結果
| 問題 |
No.3212 SUPER Guess the Number
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-25 22:21:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,207 bytes |
| コンパイル時間 | 1,819 ms |
| コンパイル使用メモリ | 194,996 KB |
| 実行使用メモリ | 25,984 KB |
| 平均クエリ数 | 21.92 |
| 最終ジャッジ日時 | 2025-07-25 22:21:12 |
| 合計ジャッジ時間 | 3,409 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#define dbgn(...) 0
#endif
int q(ll x) {
cout << "? " << x << endl;
int response;
cin >> response;
if (response == -1) {
exit(0);
}
return response;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
ll l = 1, r = 1000000;
ll prev_x, curr_x;
int resp;
prev_x = 1;
cout << "? " << prev_x << endl;
curr_x = 1000000;
resp = q(curr_x);
if (resp == 1) {
l = 500001;
} else {
r = 500000;
}
prev_x = curr_x;
while (l < r) {
ll m;
if (prev_x > r) {
m = l + (r - l) / 2;
} else {
m = l + (r - l + 1) / 2;
}
curr_x = 2 * m - prev_x;
resp = q(curr_x);
if (curr_x > prev_x) {
if (resp == 1) {
l = m;
} else {
r = m - 1;
}
} else {
if (resp == 1) {
r = m;
} else {
l = m + 1;
}
}
prev_x = curr_x;
}
cout << "! " << l << endl;
return 0;
}