QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378417 | #6394. Turn on the Light | innovation# | WA | 0ms | 3552kb | C++14 | 675b | 2024-04-06 12:45:13 | 2024-04-06 12:45:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll check(ll x)
{
ll y;
cout<<"? "<<x<<endl;
cin>>y;
return y;
}
int main()
{
//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, L, R, mid, ans;
cin>>n;
L = 1;
R = n;
ans = 0;
while(L<=R)
{
mid = L+R>>1;
ll tmp = check(mid);
if(tmp==ans)
{
cout<<"! "<<mid<<endl;
return 0;
}
else
{
ll x;
cout<<"? "<<R<<endl;
cin>>x;
if(x==tmp)
{
cout<<"! "<<R<<endl;
return 0;
}
else if(x<tmp)
{//减少了.
L = mid+1;
}
else if(x>tmp)
{
R = mid-1;
}
ans = x;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3552kb
input:
10 1 0 1 1
output:
? 5 ? 10 ? 8 ? 10 ! 10
result:
wrong answer Wrong answer, more than 1 possible light!