QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#402274 | #6394. Turn on the Light | iwew# | WA | 1ms | 3660kb | C++20 | 767b | 2024-04-30 10:43:47 | 2024-04-30 10:43:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int l = 1, r = n, lstd = 0;
auto ask = [&](int mid) -> int {
cout << "? " << mid << endl;
int d;
cin >> d;
return d;
};
int ans = -1;
while(l < r) {
int mid = (l + r) >> 1;
auto curd = ask(mid);
if(curd - lstd == 0) {
ans = mid;
break;
} else if(curd - lstd == 1) {
l = mid + 1;
} else {
r = mid - 1;
}
lstd = curd;
}
if(ans == -1) ans = l;
cout << "! " << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3660kb
input:
3 1
output:
? 2 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3640kb
input:
10 1 2 3
output:
? 5 ? 8 ? 9 ! 10
result:
wrong answer Wrong answer, more than 1 possible light!