QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574728 | #6394. Turn on the Light | GammaRays | WA | 1ms | 3728kb | C++23 | 940b | 2024-09-19 00:07:07 | 2024-09-19 00:07:10 |
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;
// cout << l << ' ' << r << endl;
if (l + 1 < r) {
} else {
return;
}
int mid = (l + r) >> 1;
int x = ask(mid);
if(x == lst) {
answer(mid);
}
int y = ask(r);
if(y == x) {
answer(r);
}
if(x < y) {
solve(l, mid + 1, y);
}
//0 1 1
else {
solve(mid - 1, r - 1, y);
}
return;
}
int main() {
cin >> n;
L = 1, R = n;
solve(1, n, 0);
if (ask(L) == LST) {
answer(L);
} else {
answer(R);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3728kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3636kb
input:
10 1 0 1 0 0
output:
? 5 ? 10 ? 6 ? 9 ? 6 ! 6
result:
wrong answer Wrong answer, more than 1 possible light!