QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#407488 | #6394. Turn on the Light | nageing# | WA | 1ms | 3752kb | C++20 | 892b | 2024-05-08 19:53:52 | 2024-05-08 19:53:53 |
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;
vector<pair<int, int>> p;
int cnt = 1;
while (l < r) {
int mid = l + r >> 1;
int x = query(mid);
if (x == 0) {
cout << "! " << mid << '\n';
return;
}
p.push_back({cnt * (x < 0 ? -1 : 1), mid});
cnt ++;
if (x > 0) {
l = mid + 1;
} else {
r = mid;
}
}
sort(p.begin(), p.end());
cout << "! " << p[p.size() - 1].second << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.flush();
int t;
t = 1;
while (t --) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3520kb
input:
10 1 2 3
output:
? 5 ? 8 ? 10 ! 10
result:
wrong answer Wrong answer, more than 1 possible light!