QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#73421#4884. Battleship: New Rulesaurelion_solTL 0ms0kbC++142.2kb2023-01-25 11:27:572023-01-25 11:27:58

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-25 11:27:58]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-01-25 11:27:57]
  • 提交

answer

#include<bits/stdc++.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;
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);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)exit(0);
}
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);
	// if(u==4&&d==5&&l==1&&r==3){
	// 	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("");
	// }
	if(u==d&&l==r){
		put(u-1,l-1);
		return;
	}
	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]);
		}
		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]);
		}
		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{
		rp(i,1,n){
			scanf("%s",s[i]+1);
		}
		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();
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

2
3
1
4

output:

! -1 -1

result: