QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#615784 | #8935. Puzzle: Easy as Scrabble | propane | WA | 1ms | 5640kb | C++20 | 1.9kb | 2024-10-05 20:09:35 | 2024-10-05 20:09:35 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;
char g[1005][1005];
int dir[1005][1005];
int n, m;
// UDLR
const int dx[4]{-1, 1, 0, 0};
const int dy[4]{0, 0, -1, 1};
void solve(int x, int y, int type, char c){
if (x <= 0 or x > n or y <= 0 or y > m){
cout << "NO" << '\n';
exit(0);
}
if (dir[x][y] == -1){
if (g[x][y] == '.'){
solve(x + dx[type], y + dy[type], type, c);
}
else if (g[x][y] != c){
cout << "NO" << '\n';
exit(0);
}
return;
}
if (g[x][y] == '.'){
g[x][y] = c;
dir[x][y] = type;
return;
}
if (g[x][y] == c){
dir[x][y] = -1;
return;
}
int bk = dir[x][y];
char bkc = g[x][y];
dir[x][y] = -1;
g[x][y] = '.';
solve(x + dx[type], y + dy[type], type, c);
solve(x + dx[bk], y + dy[bk], bk, bkc);
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i <= n + 1; i++){
for(int j = 0; j <= m + 1; j++){
cin >> g[i][j];
if (g[i][j] == 'x') dir[i][j] = -1;
}
}
for(int i = 1; i <= m; i++){
if (g[0][i] != '.') solve(1, i, 0, g[0][i]);
if (g[n + 1][i] != '.') solve(n, i, 1, g[n + 1][i]);
}
for(int i = 1; i <= n; i++){
if (g[i][0] != '.') solve(i, 1, 2, g[i][0]);
if (g[i][m + 1] != '.') solve(i, m, 3, g[i][m + 1]);
}
cout << "YES" << '\n';
for(int i = 1; i <= n; i++){
replace(g[i] + 1, g[i] + m + 1, 'x', '.');
for(int j = 1; j <= m; j++){
cout << g[i][j];
}
cout << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5588kb
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: 5640kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
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.