QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#641997 | #8935. Puzzle: Easy as Scrabble | ucup-team173 | WA | 0ms | 3812kb | C++20 | 1.7kb | 2024-10-15 08:27:37 | 2024-10-15 08:27:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<string> s(n + 2);
for(int i = 0; i <= n + 1; i++) {
cin >> s[i];
}
vector fr(n + 2, vector(m + 2, vector<int>()));
queue<array<int, 4>> q; // <x, y, val, dir>
// 0: up 1: right 2: down 3: left
for(int i = 1; i <= n; i++) {
if(s[i][0] != '.') q.push({i, 1, s[i][0], 3});
if(s[i][m + 1] != '.') q.push({i, m, s[i][m + 1], 1});
}
for(int i = 1; i <= m; i++) {
if(s[0][i] != '.') q.push({1, i, s[0][i], 0});
if(s[n + 1][i] != '.') q.push({n, i, s[n + 1][i], 2});
}
constexpr int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 11};
while(q.size()) {
auto [x, y, val, dir] = q.front();
q.pop();
if(x < 1 || x > n || y < 1 || y > m) {
cout << "NO\n";
return 0;
}
if(s[x][y] == '.') {
s[x][y] = val, fr[x][y].push_back(dir);
} else if(s[x][y] == 'x') {
q.push({x + dx[dir], y + dy[dir], val, dir});
} else if(s[x][y] != val) {
q.push({x + dx[dir], y + dy[dir], val, dir});
for(auto i : fr[x][y]) {
q.push({x + dx[i], y + dy[i], val, i});
}
s[x][y] = 'x';
} else {
fr[x][y].push_back(dir);
}
}
cout << "YES\n";
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(s[i][j] == 'x') s[i][j] = '.';
cout << s[i][j];
}
cout << '\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 0ms
memory: 3484kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3812kb
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.