QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#73492 | #4884. Battleship: New Rules | aurelion_sol | RE | 16ms | 3560kb | C++14 | 2.8kb | 2023-01-25 14:46:43 | 2023-01-25 14:46:44 |
Judging History
answer
#include<bits/stdc++.h>
#include <unistd.h>
#define rp(i,a,b) for(int i=a,_=b;i<=_;++i)
#define pr(i,a,b) for(int i=a,_=b;i>=_;--i)
#define pb push_back
using namespace std;
typedef vector<int> vi;
int T,n,ans,W,F;
char s[110][110];
int query(int x,int y){
// return s[x][y]==s[x+1][y]&&s[x][y]==s[x][y+1]&&s[x][y]==s[x+1][y+1];
if(x<1||y>=n||y<1||y>=n)return 0;
printf("? %d %d\n",x,y),fflush(stdout);
int z;scanf("%d",&z);
// if(z==-1){while(1)++ans;}
return z;
}
void put(int x,int y){
if(x<1||x>=n-1||y<1||y>=n-1)x=-1,y=-1;
printf("! %d %d\n",x,y),fflush(stdout);
int z;scanf("%d",&z);
// if(z==-1){while(1)++ans;}
}
// int K=8;
int lu;
void solve(int u,int d,int l,int r,vi U,vi D,vi L,vi R){
// printf("%d %d %d %d\n",u,d,l,r);
// rp(i,0,r-l)printf("%d",U[i]);
// puts("");
// rp(i,0,r-l)printf("%d",D[i]);
// puts("");
// rp(i,0,d-u)printf("%d",L[i]);
// puts("");
// rp(i,0,d-u)printf("%d",R[i]);
// puts("");
assert(u>=1&&u<=d&&d<=n);
assert(l>=1&&l<=r&&r<=n);
if(u==d&&l==r){
if(F){
// if(u==1&&l==1)while(1)++ans;
}
put(u-1,l-1);
return;
}
assert(u>=lu);
if(W==2&&F==2){
assert(u<7);
}
lu=u;
if(W==2)++F;
assert(U.size()==r-l+1);
assert(D.size()==r-l+1);
assert(L.size()==d-u+1);
assert(R.size()==d-u+1);
if(d-u>=r-l){
int mid=(u+d)/2,y=query(mid,l-1);
vi M=vi();
vi L1=vi(),L2=vi();
vi R1=vi(),R2=vi();
rp(i,l,r){
int x=query(mid,i);
M.pb(x|y),y=x;
}
rp(i,u,mid){
L1.pb(L[i-u]),R1.pb(R[i-u]);
}
rp(i,mid+1,d){
L2.pb(L[i-u]),R2.pb(R[i-u]);
}
assert(M.size()==U.size());
assert(L1.size()==mid-u+1);
assert(L2.size()==d-mid);
int A=(mid-u+1)*(r-l+1)%2;
rp(i,u,mid)rp(j,l,r){
int x=0;
if(i==u)x|=U[j-l];
if(i==mid)x|=M[j-l];
if(j==l)x|=L[i-u];
if(j==r)x|=R[i-u];
A^=x;
}
if(A)solve(u,mid,l,r,U,M,L1,R1);
else solve(mid+1,d,l,r,M,D,L2,R2);
}else{
int mid=(l+r)/2,y=query(u-1,mid);
vi M=vi();
vi U1=vi(),U2=vi();
vi D1=vi(),D2=vi();
rp(i,u,d){
int x=query(i,mid);
M.pb(x|y),y=x;
}
rp(i,l,mid){
U1.pb(U[i-l]),D1.pb(D[i-l]);
}
rp(i,mid+1,r){
U2.pb(U[i-l]),D2.pb(D[i-l]);
}
assert(M.size()==L.size());
assert(U1.size()==mid-l+1);
assert(U2.size()==r-mid);
int A=(mid-l+1)*(d-u+1)%2;
rp(i,u,d)rp(j,l,mid){
int x=0;
if(i==u)x|=U[j-l];
if(i==d)x|=D[j-l];
if(j==l)x|=L[i-u];
if(j==mid)x|=M[i-u];
A^=x;
}
if(A)solve(u,d,l,mid,U1,D1,L,M);
else solve(u,d,mid+1,r,U2,D2,M,R);
}
}
void work(){
scanf("%d",&n);
++n;
if(~n&1){
put(-1,-1);
}else{
W+=n==11?1:100;
// rp(i,1,n){
// scanf("%s",s[i]+1);
// }
lu=0;
solve(1,n,1,n,vi(n,0),vi(n,0),vi(n,0),vi(n,0));
}
}
int main(){
scanf("%d",&T);
while(T--)work();
if(ans)printf("%d\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
2 3 1 4 1 0 0 0 0 0 0 0 0 0 0 0 1
output:
!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