QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#221744 | #6394. Turn on the Light | tselmegkh# | WA | 1ms | 3636kb | C++14 | 950b | 2023-10-21 14:26:56 | 2023-10-21 14:26:56 |
Judging History
answer
#include <iostream>
#include <set>
using namespace std;
int qry(int x) {
cout << "? " << x + 1 << endl;
int a;
cin >> a;
return a;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
set<int> off;
for (int i = 0; i < n; i++) {
off.insert(i);
}
int dif = 0, lo = 0, hi = n - 1;
while (lo < hi) {
int d = qry(*off.begin());
if (d == dif) {
cout << "! " << *off.begin() + 1 << endl;
return 0;
}
off.erase(off.begin());
dif = d;
int mi = (lo + hi) / 2;
d = qry(mi);
if (d == dif) {
cout << "! " << mi + 1 << endl;
return 0;
}
if (d > dif) {
lo = mi + 1;
} else {
hi = mi - 1;
}
dif = d;
off.erase(mi);
}
cout << "! " << lo << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3636kb
input:
3 1 2
output:
? 1 ? 2 ! 2
result:
wrong answer Wrong favorite light!