QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#540612#8935. Puzzle: Easy as Scrabbleucup-team4508#WA 0ms5876kbC++143.0kb2024-08-31 17:29:172024-08-31 17:29:19

Judging History

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

  • [2024-08-31 17:29:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5876kb
  • [2024-08-31 17:29:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n,i,j,k,m,t;
LL a[500005];
string s[1005];
string s1,s2,s3,s4;
LL stat[1005][1005];
LL tag1[1005],tag2[1005],tag3[1005],tag4[1005];
bool doit(LL stat,LL x){
	if(stat==1){
		LL tmp=tag1[x];
		for(LL i=tmp+1;i<=n;i++){
			if((s[i][x]=='.' && tag3[i]<=x && tag4[i]>=x) || s[i][x]==s1[x]){
				s[i][x]=s1[x],s[tmp][x]='.',tag1[x]=i;return true;
			}
			else if(s[i][x]>='A' && s[i][x]<='Z'){
				if(tag2[x]==i || (tag3[i]==x && tag4[i]==x)){
					return false;
				}
				if(tag3[i]==x){
					if(doit(3,i)==false) return false;
				}
				if(tag4[i]==x){
					if(doit(4,i)==false) return false;
				}
			}
		}
		return false;
	}
	if(stat==2){
		LL tmp=tag2[x];
		for(LL i=tmp-1;i>=1;i--){
			if((s[i][x]=='.' && tag3[i]<=x && tag4[i]>=x) || s[i][x]==s2[x]){
				s[i][x]=s2[x],s[tmp][x]='.',tag2[x]=i;return true;
			}
			else if(s[i][x]>='A' && s[i][x]<='Z'){
				if(tag1[x]==i || (tag3[i]==x && tag4[i]==x)){
					return false;
				}
				if(tag3[i]==x){
					if(doit(3,i)==false) return false;
				}
				if(tag4[i]==x){
					if(doit(4,i)==false) return false;
				}
			}
		}
		return false;
	}
	if(stat==3){
		LL tmp=tag3[x];
		for(LL i=tmp+1;i<=n;i++){
			if((s[x][i]=='.' && tag1[i]<=x && tag2[i]>=x) || s[x][i]==s3[x]){
				s[x][i]=s3[x],s[x][tmp]='.',tag3[x]=i;return true;
			}
			else if(s[x][i]>='A' && s[x][i]<='Z'){
				if(tag4[x]==i || (tag1[i]==x && tag2[i]==x)){
					return false;
				}
				if(tag1[i]==x){
					if(doit(1,i)==false) return false;
				}
				if(tag2[i]==x){
					if(doit(2,i)==false) return false;
				}
			}
		}
		return false;
	}
	if(stat==4){
		LL tmp=tag4[x];
		for(LL i=tmp-1;i>=1;i--){
			if((s[x][i]=='.' && tag1[i]<=x && tag2[i]>=x) || s[x][i]==s4[x]){
				s[x][i]=s4[x],s[x][tmp]='.',tag4[x]=i;return true;
			}
			else if(s[x][i]>='A' && s[x][i]<='Z'){
				if(tag3[x]==i || (tag1[i]==x && tag2[i]==x)){
					return false;
				}
				if(tag1[i]==x){
					if(doit(1,i)==false) return false;
				}
				if(tag2[i]==x){
					if(doit(2,i)==false) return false;
				}
			}
		}
		return false;
	}
	return false;
}
int main(){
	scanf("%lld%lld",&n,&m);
	for(i=0;i<=n+1;i++)
	  cin>>s[i];
	for(i=0;i<=n+1;i++){
		s1+=s[0][i],s2+=s[n+1][i],s3+=s[i][0],s4+=s[i][n+1];
	}
	for(i=1;i<=n;i++)
	  tag2[i]=n+1,tag4[i]=n+1; 
	for(i=1;i<=n;i++){
		if(s1[i]=='.') continue;
		if(doit(1,i)==false){
	  	    printf("NO\n");
	  	    return 0;
	    }
	}
	  
	for(i=1;i<=n;i++){
		if(s2[i]=='.') continue;
		if(doit(2,i)==false){
	  		printf("NO\n");
	  		return 0;
	    }
	}
	  
	for(i=1;i<=n;i++){
		if(s3[i]=='.') continue;
		if(doit(3,i)==false){
	  		printf("NO\n");
	  		return 0;
	  	}
	}
	for(i=1;i<=n;i++){
		if(s4[i]=='.') continue;
		if(doit(4,i)==false){
	  		printf("NO\n");
	  		return 0;
	 	}
	}
	  
	printf("YES\n");
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)
		  printf("%c",s[i][j]);
		printf("\n");
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

YES
CBAx.
.x..C
A...B
B.x.A
C....

result:

wrong answer Token parameter [name=row] equals to "CBAx.", doesn't correspond to pattern "[A-Z.]{5}"