QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#218863 | #6394. Turn on the Light | therehello# | WA | 1ms | 3600kb | C++20 | 954b | 2023-10-18 19:29:18 | 2023-10-18 19:29:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = long long;
void solve() {
int n;
cin >> n;
int l = 1, r = n;
auto ask = [&](int x) {
cout << "? " << x << endl;
int ret;
cin >> ret;
return ret;
};
auto submit = [&](int x) { cout << "! " << x << endl; };
int v = 0;
while (l < r) {
int mid = l + r >> 1;
int v1 = ask(mid);
if (v1 == v) {
submit(mid);
return;
}
int v2 = ask(l);
if (v2 == v) {
r = mid;
} else if (v2 == v1) {
submit(l);
return;
} else {
l = mid + 1;
}
v = v2;
}
submit(l);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3600kb
input:
3 1 2
output:
? 2 ? 1 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3436kb
input:
10 1 2 3 4 5 5
output:
? 5 ? 1 ? 8 ? 6 ? 9 ? 9 ! 9
result:
wrong answer Wrong favorite light!