QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574767 | #6394. Turn on the Light | GammaRays | WA | 1ms | 3736kb | C++23 | 1.2kb | 2024-09-19 00:22:07 | 2024-09-19 00:22:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int tag;
int n;
int L, R, LST;
void solve(int l,int r,int lst)
{
if(tag==1)
{
return;
}
int mid,x,y;
mid=(l+r)>>1;
if (l + 1 < r) {
L = l;
R = r;
LST = lst;
} else {
return;
}
cout<<"? "<<mid<<"\n";
cout.flush();
cin>>x;
if(x==lst)
{
tag=1;
cout<<"! "<<mid;
cout.flush();
return;
}
cout<<"? "<<r<<"\n";
cout.flush();
cin>>y;
if(y==x)
{
tag=1;
cout<<"! "<<r;
cout.flush();
return;
}
// cout<<x<<" "<<y<<endl;
if(x<y)
{
solve(l,max(l,mid-1),y);
}
else
{
solve(min(r-1,mid+1),r-1,y);
}
return;
}
int main()
{
int n;
cin>>n;
tag=0;
solve(1,n,0);
int res;
cout << "? " << L << endl;
cin >> res;
if (res == LST) {
cout<<"! "<< L;
return 0;
}
LST = res;
cout << "? " << L << endl;
cin >> res;
if (res == LST) {
cout<<"! "<< R;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3736kb
input:
3 1 1
output:
? 2 ? 3 ! 3? 1
result:
wrong answer format Expected integer, but "3?" found