QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548355 | #6394. Turn on the Light | pandapythoner# | WA | 0ms | 3660kb | C++23 | 1.2kb | 2024-09-05 17:25:42 | 2024-09-05 17:25:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define len(a) int((a).size())
#define all(a) begin(a), end(a)
#define rep(i, n) for (int i = 0; i < (n); i++)
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
#ifdef LOCAL
int x = rand() % n;
cerr << "x=" << x << endl;
int cur_ans_ = 0;
#endif
auto query = [&](int pos) {
cout << "? " << pos << endl;
#ifdef LOCAL
if (pos < x) {
cur_ans_++;
} else if (pos > x) {
cur_ans_--;
}
return cur_ans_;
#else
int res;
cin >> res;
return res;
#endif
};
int prev = 0;
int l = 0, r = n;
while (true) {
int mid = (l + r) / 2;
int cur = query(mid);
if (cur == prev) {
cout << "! " << mid + 1 << endl;
#ifdef LOCAL
assert(mid == x);
#endif
return 0;
}
assert(r - l > 1);
if (cur > prev) {
l = mid;
} else {
r = mid;
}
prev = cur;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
3 1 2 2
output:
? 1 ? 2 ? 2 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
10 1 2 3 4 4
output:
? 5 ? 7 ? 8 ? 9 ? 9 ! 10
result:
wrong answer Wrong answer, more than 1 possible light!