QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#615722 | #8935. Puzzle: Easy as Scrabble | ucup-team4975 | WA | 143ms | 817952kb | C++23 | 1.7kb | 2024-10-05 19:54:38 | 2024-10-05 19:54:39 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<map>
#include<queue>
#include<vector>
#include<fstream>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int N=1100;
const int dx[]={0,0,1,-1}; //down up right left
const int dy[]={1,-1,0,0};
int n,m;
char s[N][N];
struct Node{
int dir,x,y;
char c;
Node(int _x,int _y):x(_x),y(_y){}
Node(int _dir,int _x,int _y,char _c):x(_x),y(_y),dir(_dir),c(_c){}
};
queue<Node>a[N][N];
queue<Node>q;
inline bool push(int dir,char c,int x,int y)
{
while(1)
{
if(s[x][y]!='x')
{
if(s[x][y]=='.')
s[x][y]=c;
else if(s[x][y]!=c)
s[x][y]='x',q.push(Node(x,y));
a[x][y].push(Node(dir,c,x,y));
return 1;
}
x+=dx[dir],y+=dy[dir];
if(x>n||x<1||y>m||y<1)return 0;
}
return 1;
}
inline bool push(Node pos){return push(pos.dir,pos.c,pos.x,pos.y);}
signed main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<=n+1;i++)
scanf("%s",s[i]);
bool valid=1;
for(int i=1;i<=n;i++)
{
if(s[i][0]!='.')valid&=push(2,s[i][0],i,1);
if(s[i][m+1]!='.')valid&=push(3,s[i][m+1],i,m);
}
for(int j=1;j<=m;j++)
{
if(s[0][j]!='.')valid&=push(0,s[0][j],1,j);
if(s[n+1][j]!='.')valid&=push(1,s[n+1][j],n,j);
}
if(!valid)
{
puts("NO");
return 0;
}
while(q.size())
{
Node pos=q.front();q.pop();
while(a[pos.x][pos.y].size())
{
Node box=a[pos.x][pos.y].front();
a[pos.x][pos.y].pop();
if(!push(box))
{
valid=0;
break;
}
}
}
if(!valid)
{
puts("NO");
return 0;
}
puts("YES");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
putchar(s[i][j]=='x'?'.':s[i][j]);
putchar('\n');
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 128ms
memory: 816872kb
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: 143ms
memory: 817952kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: -100
Wrong Answer
time: 140ms
memory: 817056kb
input:
5 5 .U.N.X. U....xX Ox....X M...xxN Vx....S Ix.x..X ..IBHX.
output:
NO
result:
wrong answer Jury has answer but participant has not.