QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#384019 | #6394. Turn on the Light | dreamwave | WA | 1ms | 3652kb | C++14 | 992b | 2024-04-09 20:01:48 | 2024-04-09 20:01:48 |
Judging History
answer
#include <bits/stdc++.h>
void solve() {
int n;
std::cin >> n;
auto dfs = [&](auto self, int l, int r, int v) -> void {
if(l == r) {
std::cout << "! " << l << std::endl;
exit(0);
}
int mid = (l + r) >> 1;
std::cout << "? " << l << std::endl;
int val;
std::cin >> val;
if(val == v) {
std::cout << "! " << l << std::endl;
exit(0);
}
std::cout << "? " << mid << std::endl;
int val2;
std::cin >> val2;
if(val == val2) {
std::cout << "! " << mid << std::endl;
exit(0);
}
if(val + 1 == val2) {
self(self, mid + 1, r, val2);
} else {
self(self, l + 1, mid - 1, val2);
}
} ;
dfs(dfs, 1, n, 0);
}
int main() {
std::cin.tie(nullptr) -> sync_with_stdio(false);
int T = 1;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
input:
3 1 2
output:
? 1 ? 2 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3652kb
input:
10 1 2 3 4 5 5
output:
? 1 ? 5 ? 6 ? 8 ? 9 ? 9 ! 9
result:
wrong answer Wrong favorite light!