QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548362 | #6394. Turn on the Light | pandapythoner# | WA | 1ms | 3668kb | C++23 | 1.6kb | 2024-09-05 17:32:04 | 2024-09-05 17:32:04 |
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 + 1 << endl;
#ifdef LOCAL
if (pos < x) {
cur_ans_++;
} else if (pos > x) {
cur_ans_--;
}
return abs(cur_ans_);
#else
int res;
cin >> res;
return res;
#endif
};
int q0 = query(0);
if (q0 == 0) {
cout << "! 1" << endl;
return 0;
}
int q1 = query(1);
if (q1 == q0) {
cout << "! 2" << endl;
return 0;
}
assert(q1 == 2);
int l = 0, r = n;
while (true) {
int mid = (l + r) / 2;
int cur = query(mid);
if (cur == 2) {
cout << "! " << mid + 1 << endl;
#ifdef LOCAL
assert(mid == x);
#endif
return 0;
}
assert(r - l > 1);
if (cur == 1) {
r = mid;
int tmp = query(0);
assert(tmp == 2);
} else {
assert(cur == 3);
l = mid;
int tmp = query(n - 1);
if (tmp == 3) {
cout << "! " << n << endl;
return 0;
}
assert(tmp == 2);
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3668kb
input:
3 1 2 2
output:
? 1 ? 2 ? 2 ! 2
result:
wrong answer Wrong favorite light!