QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235255#1811. How to Move the BeansFamiglistmoWA 0ms3416kbC++142.4kb2023-11-02 16:29:372023-11-02 16:29:38

Judging History

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

  • [2023-11-02 16:29:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3416kb
  • [2023-11-02 16:29:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1005;

void file(){
	freopen("chequer.in","r",stdin);
	freopen("chequer.out","w",stdout);
}

char s[N][N];
int sg[N][N],L[N],R[N],pre[N],nex[N];
int f[N][5],g[N][5],tl[N],tr[N];
int T,n,m;

bool vis[10];
int mex(int a,int b){
	if(a!=-1)vis[a]=true;
	if(b!=-1)vis[b]=true;
	
	int res=0;
	while(vis[res])++res;
	
	if(a!=-1)vis[a]=false;
	if(b!=-1)vis[b]=false;
	
	return res;
}
int mex(int a,int b,int c){
	if(a!=-1)vis[a]=true;
	if(b!=-1)vis[b]=true;
	if(c!=-1)vis[c]=true;
	
	int res=0;
	while(vis[res])++res;
	
	if(a!=-1)vis[a]=false;
	if(b!=-1)vis[b]=false;
	if(c!=-1)vis[c]=false;
	
	return res;
}

void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;++i)cin>>(s[i]+1);
	for(int i=1;i<=m;++i)sg[n+1][i]=-1,pre[i]=i-1,nex[i]=i+1;
	pre[1]=m,nex[m]=1;
	
	for(int h=n;h>=1;--h){
		if(m==1){
			if(s[h][1]=='#')sg[h][1]=-1;
			else sg[h][1]=mex(-1,sg[h+1][1]);
			continue;
		}
		
		vector<int>vec;
		for(int i=1;i<=m;++i)
			if(s[h][i]=='#')
				vec.push_back(i),L[i]=R[i]=-1;
		if(vec.size()){
			for(int _=0;_<(int)vec.size();++_){
				int l=vec[_]+1,r;
				if(_==(int)vec.size()-1)r=vec[0]-1;
				else r=vec[_+1]-1;
				
				if(l==m+1)l=1;
				if(r==0)r=m;
								
				L[l]=mex(-1,sg[h+1][l]);
				for(int i=nex[l];i!=nex[r];i=nex[i])
					L[i]=mex(L[pre[i]],sg[h+1][i]);
					
				R[r]=mex(-1,sg[h+1][r]);
				for(int i=pre[r];i!=pre[l];i=pre[i])
					R[i]=mex(R[nex[i]],sg[h+1][i]);
					
				if(l<=r) {
					for(int i=l;i<=r;++i)
						sg[h][i]=mex(L[pre[i]],R[nex[i]],sg[h+1][i]);
				} else {
					for(int i=l;i<=m;++i) sg[h][i]=mex(L[pre[i]],R[nex[i]],sg[h+1][i]);
					for(int i=1;i<=r;++i) sg[h][i]=mex(L[pre[i]],R[nex[i]],sg[h+1][i]);
				}
			}
		} else {
			for(int i=1;i<=m;++i){
				L[nex[i]]=mex(-1,sg[h+1][nex[i]]);
				for(int j=nex[nex[i]];j!=i;j=nex[j])
					L[j]=mex(L[pre[j]],sg[h+1][j]);
					
				R[pre[i]]=mex(-1,sg[h+1][pre[i]]);
				for(int j=pre[pre[i]];j!=i;j=pre[j])
					R[j]=mex(R[nex[j]],sg[h+1][j]);
					
				sg[h][i]=mex(L[pre[i]],R[nex[i]],sg[h+1][i]);
			}		
		}
	}
	
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(s[i][j]=='B')
				ans^=sg[i][j];
	if(ans) puts("A");
	else puts("B");
}

signed main(){
//	freopen("chequer.in","r",stdin);
//	freopen("mine.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	cin>>T;
	while(T--)solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3416kb

input:

2 3
B.#
#..

output:

B
B

result:

wrong answer 1st words differ - expected: 'Alice', found: 'B'