QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235393#1811. How to Move the BeanslefyRE 0ms0kbC++232.3kb2023-11-02 18:37:242023-11-02 18:37:25

Judging History

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

  • [2023-11-02 18:37:25]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-02 18:37:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1010;
char a[N][N];
int n,m;
int get(vector<int>a){
	int vis[4];vis[0]=vis[1]=vis[2]=vis[3]=0;
	for(int x:a)if(x>=0&&x<=3)vis[x]=1;
	for(int i=0;i<4;i++)if(!vis[i])return i;
	return -1;
}
int sg[N][N],l[N],r[N],s[N],e[N];
int L1[N][5],L2[N][5],R1[N][5],R2[N][5];
void sol2(int i){
	for(int k=0;k<=3;k++)L1[1][k]=R1[m][k]=L2[m][k]=R2[1][k]=k;
	for(int j=2;j<=m;j++)for(int k=0;k<=3;k++){
		L1[j][k]=get({L1[j-1][k],sg[i+1][j]});
		R2[j][k]=R2[j-1][get({k,sg[i+1][j-1]})];
	}
	for(int j=m-1;j;j--)for(int k=0;k<=3;k++){
		L2[j][k]=L2[j+1][get({k,sg[i+1][j+1]})];
		R1[j][k]=get({R1[j+1][k],sg[i+1][j]});
	}
	for(int j=1;j<=m;j++){
		int L=-1,R=-1;
		if(m!=1){
			if(i!=m)L=L1[j-1][get({sg[i+1][1],L2[j+1][sg[i+1][j+1]]})];
			else L=L1[j-1][sg[i+1][1]];
			if(i!=1)R=R1[j+1][get({sg[i+1][m],R2[j-1][sg[i+1][j-1]]})];
			else R=R1[j+1][sg[i+1][m]];
		}
		sg[i][j]=get({L,R,sg[i+1][j]});
	}
}
void sol1(int i){
	int st=s[i],ed=e[i];
	for(int j=1;j<=m;j++)if(a[i][j]=='#')l[i]=r[i]=-1;
	for(int j=st+1;j<=m;j++)if(a[i][j]!='#'){
		l[j]=get({l[j-1],sg[i+1][j]});
	}
	if(a[i][1]!='#'){
		l[1]=get({l[m],sg[i+1][1]});
	}
	for(int j=2;j<st;j++)if(a[i][j]!='#'){
		l[j]=get({l[j-1],sg[i+1][j]});
	}
	for(int j=ed-1;j;j--)if(a[i][j]!='#'){
		r[j]=get({r[j+1],sg[i+1][j]});
	}
	if(a[i][m]!='#'){
		r[m]=get({r[1],sg[i+1][m]});
	}
	for(int j=m-1;j>ed;j--)if(a[i][j]!='#'){
		r[j]=get({r[j+1],sg[i+1][j]});
	}
	for(int j=1;j<=m;j++)if(a[i][j]!='#'){
		int le=j-1?j-1:m,ri=j+1<=m?j+1:1;
		sg[i][j]=get({sg[i+1][j],l[le],r[ri]});
	}
}
void solve(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
		int st=-1,ed=-1;
		for(int j=1;j<=m;j++){
			if(a[i][j]=='#'){
				if(st==-1)st=j;
				ed=j;
			}
		}
		s[i]=st,e[i]=ed;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)sg[i][j]=0;
		sg[i][0]=sg[i][m+1]=4;
	}
	for(int j=0;j<=m+1;j++)sg[n+1][j]=4;
	int ans=0;
	for(int i=n;i;i--){
		int st=s[i],ed=e[i];
		if(st!=-1)sol1(i);
		else sol2(i);
		for(int j=1;j<=m;j++)if(a[i][j]=='B')ans^=sg[i][j];
	}
	if(ans)printf("A\n");
	else printf("B\n");
}
int main(){
	// freopen("chequer.in","r",stdin);
	// freopen("chequer.out","w",stdout);
	int t;
	scanf("%d",&t);
	while(t--)solve();
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

2 3
B.#
#..

output:


result: