QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83782 | #4884. Battleship: New Rules | _UMqwq_ | WA | 2ms | 3544kb | C++20 | 1.1kb | 2023-03-03 14:47:31 | 2023-03-03 14:47:32 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n;
int query(int x,int y){
printf("? %lld %lld\n",x,y);fflush(stdout);
int w;scanf("%lld",&w);return w;
}
void solve(int xl,int xr,int yl,int yr){//cerr<<"solve:"<<xl<<' '<<xr<<' '<<yl<<' '<<yr<<endl;
if(xl==xr&&yl==yr){
printf("! %lld %lld\n",xl-1,yl-1);
fflush(stdout);return;
}
if(xr-xl>yr-yl){//cerr<<"x"<<endl;
int mid=(xl+xr)>>1;
int ls=((mid-xl+1)&1)&((yr-yl+1)&1);
int rs=((xr-mid)&1)&((yr-yl+1)&1);
for(int i=yl,pre=0;i<yr;i++){
int now=query(mid,i);
if(now)ls^=(!pre)^1,rs^=(!pre)^1;
pre=now;
}
if(ls)solve(xl,mid,yl,yr);
else solve(mid+1,xr,yl,yr);
}else{//cerr<<"y"<<endl;
int mid=(yl+yr)>>1;
int ls=((mid-yl+1)&1)&((xr-xl+1)&1);
int rs=((yr-mid)&1)&((xr-xl+1)&1);
for(int i=xl,pre=0;i<xr;i++){
int now=query(i,mid);
if(now)ls^=(!pre)^1,rs^=(!pre)^1;
pre=now;
}
if(ls)solve(xl,xr,yl,mid);
else solve(xl,xr,mid+1,yr);
}
}
signed main(){
scanf("%lld",&T);
while(T--){
scanf("%lld",&n);
if(n&1){printf("! -1 -1\n");fflush(stdout);continue;}
solve(1,n+1,1,n+1);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3544kb
input:
2 3 1 4 -1
output:
! -1 -1 ! -1 -1
result:
wrong output format Unexpected end of file - int32 expected (test case 2)