QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#540640#8935. Puzzle: Easy as Scrabbleucup-team4508#WA 1ms5888kbC++143.0kb2024-08-31 17:35:242024-08-31 17:35:24

Judging History

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

  • [2024-08-31 17:35:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5888kb
  • [2024-08-31 17:35:24]
  • 提交

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(){
	cin>>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");
	  	    return 0;
	    }
	}
	  
	for(i=1;i<=n;i++){
		if(s2[i]=='.') continue;
		if(doit(2,i)==false){
	  		printf("NO");
	  		return 0;
	    }
	}
	  
	for(i=1;i<=n;i++){
		if(s3[i]=='.') continue;
		if(doit(3,i)==false){
	  		printf("NO");
	  		return 0;
	  	}
	}
	for(i=1;i<=n;i++){
		if(s4[i]=='.') continue;
		if(doit(4,i)==false){
	  		printf("NO");
	  		return 0;
	 	}
	}
	  
	printf("YES\n");
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(s[i][j]=='x') printf(".");
			else printf("%c",s[i][j]);
		}
		  
		printf("\n");
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5888kb

input:

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

output:

YES
CBA..
....C
A...B
B...A
C....

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 1ms
memory: 5820kb

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 1ms
memory: 5776kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

YES
U.NX.
.O..X
M.N..
.VB.S
.I.HX

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 0ms
memory: 5832kb

input:

10 10
.BAZEMIEKUJ.
A..........K
B..x.x.x..x.
K.........xT
A.x..x.....J
Hx....x....B
Q..x....x.xW
S...x......W
S...x.xxx..Z
...x......xZ
I..x..x.x.xR
.QKO.ID..RW.

output:

YES
.AZEMIEK..
B.......U.
K.......T.
A........J
.H.......B
Q.......W.
S........W
S.O.....Z.
QK...D..Z.
...II...R.

result:

ok Correct.

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5816kb

input:

5 10
.PTWIVVISPY.
T...x.x....Y
Xx.x.xx..x.K
P.x.xx.....K
S..........A
E.........xS
.SPEASDCYSA.

output:

YES
.TW..
.X.I.
P....
SP..V
..EAS

result:

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