QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#830199#8935. Puzzle: Easy as ScrabbleQBFWA 0ms4036kbC++142.0kb2024-12-24 16:49:222024-12-24 16:49:23

Judging History

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

  • [2024-12-24 16:49:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4036kb
  • [2024-12-24 16:49:22]
  • 提交

answer

#include<bits/stdc++.h>
#define ci const int
#define ll long long
using namespace std;
ci N=1005;
int n,m,l[N],r[N],u[N],d[N];
char s[N][N];
bool del[N][N];
queue<pair<int,int> >q;
void op(ci x,ci y){
	// printf("op (%d,%d)\n",x,y);
	if(!del[x][y])q.push(make_pair(x,y)),del[x][y]=1;
}
void chk(ci x,ci y){
	// printf("chk (%d,%d)\n",x,y);
	if(x<1||x>n||y<1||y>m){
		// puts("NO");
		exit(0);
	}
	char v=0;
	if(l[x]==y&&s[x][0]!='.')v=s[x][0];
	if(r[x]==y&&s[x][m+1]!='.'){
		if(v!=0&&v!=s[x][m+1]){
			op(x,y);
			return;
		}
		v=s[x][m+1];
	}
	if(u[y]==x&&s[0][y]!='.'){
		if(v!=0&&v!=s[0][y]){
			op(x,y);
			return;
		}
		v=s[0][y];
	}
	if(d[y]==x&&s[n+1][y]!='.'){
		if(v!=0&&v!=s[n+1][y]){
			op(x,y);
			return;
		}
		v=s[n+1][y];
	}
}
void L(ci x){
	++l[x];
	while(del[x][l[x]])++l[x];
	// printf("L %d -> %d\n",x,l[x]);
	chk(x,l[x]);
}
void R(ci x){
	--r[x];
	while(del[x][r[x]])--r[x];
	chk(x,r[x]);
}
void U(ci y){
	++u[y];
	while(del[u[y]][y])++u[y];
	chk(u[y],y);
}
void D(ci y){
	--d[y];
	while(del[d[y]][y])--d[y];
	// printf("D %d -> %d\n",y,d[y]);
	chk(d[y],y);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n+1;++i)scanf("%s",s[i]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(s[i][j]=='x')
				op(i,j);
	for(int i=1;i<=n;++i){
		l[i]=0,r[i]=m+1;
		if(s[i][0]!='.')L(i);
		if(s[i][m+1]!='.')R(i);
	}
	for(int i=1;i<=m;++i){
		u[i]=0,d[i]=n+1;
		if(s[0][i]!='.')U(i);
		if(s[n+1][i]!='.')D(i);
	}
	while(!q.empty()){
		ci x=q.front().first,y=q.front().second;q.pop();
		if(l[x]==y)L(x);
		if(r[x]==y)R(x);
		if(u[y]==x)U(y);
		if(d[y]==x)D(y);
	}
	for(int i=1;i<=n;++i){
		if(s[i][0]!='.')s[i][l[i]]=s[i][0];
		if(s[i][m+1]!='.')s[i][r[i]]=s[i][m+1];
	}
	for(int i=1;i<=m;++i){
		if(s[0][i]!='.')s[u[i]][i]=s[0][i];
		if(s[n+1][i]!='.')s[d[i]][i]=s[n+1][i];
	}
	puts("YES");
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=m;++j)
			printf("%c",s[i][j]=='x'?'.':s[i][j]);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4036kb

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: -100
Wrong Answer
time: 0ms
memory: 3924kb

input:

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

output:


result:

wrong output format Unexpected end of file - token expected