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