QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136500 | #6394. Turn on the Light | ammardab3an# | WA | 2ms | 3600kb | C++17 | 832b | 2023-08-08 21:45:26 | 2023-08-08 21:45:30 |
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;
}
cur = y1;
}
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;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3600kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3532kb
input:
10 1 2 3 4 5 5
output:
? 1 ? 5 ? 6 ? 8 ? 9 ? 9 ! 9
result:
wrong answer Wrong favorite light!