QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#528306 | #6394. Turn on the Light | OneWan# | WA | 1ms | 3720kb | C++23 | 1.5kb | 2024-08-23 12:38:21 | 2024-08-23 12:38:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int query(int x) {
cout << "? " << x << endl;
cin >> x;
return x;
}
void ans(int x) {
cout << "! " << x << endl;
exit(0);
}
int main() {
int n;
cin >> n;
int x = query(1);
if (x == 0) {
ans(1);
} else {
int L = 2, R = n, last = x;
while (L < R) {
int mid = L + R >> 1;
x = query(mid);
if (x == last) {
ans(mid);
}
if (x == 0) {
x = query(L);
L++;
R = mid - 1;
last = x;
continue;
}
if (last > x) {
R = mid - 1;
} else {
L = mid + 1;
}
last = x;
}
ans(L);
}
// for (int i = 1; i <= min(20, n); i++) {
// int x = query(i);
// if(x != i) {
// ans(i);
// }
// }
// cout << '\n';
// {
// int L = 20, R = n;
// int last = x;
// while (L + 1 < R) {
// int mid = L + R + 1 >> 1;
// x = query(mid);
// cout << x << '\n';
// if (x == last) {
// ans(mid);
// }
// else if (x > last) {
// L = mid;
// } else {
// R = mid - 1;
// }
// }
// ans(L + 1);
// }
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
input:
3 1 2
output:
? 1 ? 2 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3720kb
input:
10 1 0 1 0 0
output:
? 1 ? 6 ? 2 ? 4 ? 3 ! 4
result:
wrong answer Wrong favorite light!