QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#407493 | #6394. Turn on the Light | nageing# | WA | 0ms | 3600kb | C++20 | 882b | 2024-05-08 19:59:38 | 2024-05-08 19:59:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int query(int x) {
cout << "? " << x << endl;
int res;
cin >> res;
return res;
}
void solve() {
int n;
cin >> n;
int l = 0, r = n + 1;
int cnt1 = 0, cnt2 = 0;
while (l < r) {
int mid = l + r >> 1;
int x = query(mid);
if (x < 0 && x == cnt2) {
cout << "! " << mid << '\n';
return;
} else if (x >= 0 && x == cnt1) {
cout << "! " << mid << '\n';
return;
}
if (x > 0) {
l = mid + 1;
cnt1 = x;
} else {
r = mid;
cnt2 = x;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.flush();
int t;
t = 1;
while (t --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
10 1 2 3
output:
? 5 ? 8 ? 10
result:
wrong answer format Unexpected end of file - token expected