QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136499 | #6394. Turn on the Light | ammardab3an# | WA | 2ms | 3592kb | C++17 | 819b | 2023-08-08 21:44:12 | 2023-08-08 21:44:13 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;
int ask(int x) {
cout << "? " << x << endl;
int y; cin >> y;
return y;
}
int solve() {
int n; cin >> n;
int l = 1, r = n;
int res = 0;
int cur = 0;
while (l <= r) {
int mid = l + r >> 1;
int y = ask(l);
if (y == cur) {
res = l;
break;
}
int y1 = ask(mid);
if (y1 == y) {
res = mid;
break;
}
if (y1 == cur) {
r = mid - 1;
l++;
}
else {
l = mid + 1;
}
}
cout << "! " << res << endl;
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
int i = 1;
while (t--) {
//cout << "case " << i << ": ";
solve();
}
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
3 1 2 2 2
output:
? 1 ? 2 ? 3 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3488kb
input:
10 1 2 3 4 5 5
output:
? 1 ? 5 ? 6 ? 8 ? 9 ? 9 ! 9
result:
wrong answer Wrong favorite light!