QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574751 | #6394. Turn on the Light | GammaRays | WA | 1ms | 3652kb | C++23 | 999b | 2024-09-19 00:15:39 | 2024-09-19 00:15:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void answer(int x) {
cout << '!' << ' ' << x << endl;
exit(0);
}
int ask(int x) {
cout << '?' << ' ' << x << endl;
int ret;
cin >> ret;
return ret;
}
int n;
int L = 1;
int R = n;
int LST = 0;
void solve(int l, int r, int lst) {
L = l;
R = r;
LST = lst;
if (l + 1 < r) {
} else {
return;
}
int x = ask(r);
if(x == lst) {
answer(r);
}
r --;
int mid = (l + r) >> 1;
int y = ask(mid);
if(y == x) {
answer(mid);
}
if(x < y) {
solve(l, mid - 1, y);
}
//0 1 1
else {
solve(mid + 1, r, y);
}
return;
}
int main() {
cin >> n;
L = 1, R = n;
solve(1, n, 0);
cout << L << ' ' << R << endl;
int res = ask(L);
if (res == LST) {
answer(L);
}
LST = res;
if (ask(R) == LST){
answer(R);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
input:
3 0
output:
? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3588kb
input:
10 1 0 1 0
output:
? 10 ? 5 ? 9 ? 7 8 8 ? 8
result:
wrong answer Token parameter [name=type] equals to "8", doesn't correspond to pattern "?|!"