QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#83783 | #4884. Battleship: New Rules | _UMqwq_ | RE | 0ms | 3604kb | C++20 | 1.1kb | 2023-03-03 14:50:21 | 2023-03-03 14:50:24 |
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;
}
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){
if(xl==xr&&yl==yr){assert(check(xl-1,yl-1));return;}
if(xr-xl>yr-yl){
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{
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){assert(check(-1,-1));continue;}
solve(1,n+1,1,n+1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
2 3 1 4 0 0 0 1 1 0 1 0 1
output:
! -1 -1 ? 1 3 ? 2 3 ? 3 3 ? 4 3 ? 3 1 ? 3 2 ? 1 2 ? 2 2 ! 2 2
result:
ok max_C=2.00, avg_C=1.00 (2 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