QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#631131 | #8935. Puzzle: Easy as Scrabble | woodie_0064# | WA | 0ms | 3720kb | C++17 | 1.7kb | 2024-10-11 22:12:39 | 2024-10-11 22:12:39 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1005;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int n, m;
pair<char, int> vis[maxn][maxn];
string a[maxn];
bool check(char col) {
return col >= 'A' && col <= 'Z';
}
bool dfs(int x, int y, int o, char col) {
// cout << x << ' ' << y << ' ' << o << ' ' << col << '\n';
// cout << check(col) << '\n';
if(!check(col)) {
return 1;
}
// cout << x << ' ' << y << ' ' << o << ' ' << col << '\n';
if(x > n || x < 1 || y > m || y < 1) {
return 0;
}
if(a[x][y] == 'x') {
return dfs(x + dx[o], y + dy[o], o, col);
}
if(a[x][y] != '.') {
return a[x][y] == col;
}
if(!vis[x][y].first) {
vis[x][y] = make_pair(col, o);
return 1;
}
if(vis[x][y].first == col) {
a[x][y] = col;
return 1;
}
int o2 = vis[x][y].second;
char c2 = vis[x][y].first;
vis[x][y] = make_pair(0, 0);
bool res = dfs(x + dx[o], y + dy[o], o, col) && dfs(x + dx[o2], y + dy[o2], o2, c2);
return res;
}
int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i <= n + 1; i++) {
cin >> a[i];
}
// cout << a[0][1] << '\n';
// cout << check('A') << '\n';
for(int i = 1; i <= m; i++) {
if((!dfs(1, i, 0, a[0][i])) || !dfs(n, i, 1, a[n + 1][i])) {
cout << "NO\n";
return 0;
}
}
for(int i = 1; i <= n; i++) {
if(!dfs(i, 1, 2, a[i][0]) || !dfs(i, m, 3, a[i][m + 1])) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(vis[i][j].first) {
cout << vis[i][j].first;
}
else {
cout << a[i][j];
}
}
cout << '\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3720kb
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}"