QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#149439 | #4432. Jungle Trail | rgnerdplayer# | RE | 0ms | 0kb | C++20 | 2.7kb | 2023-08-24 16:48:51 | 2023-08-24 16:48:54 |
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
auto solve = [&]() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<pair<int, int>> q{{0, 0}};
vector vis(n, vector<int>(m));
vector prv(n, vector<pair<int, int>>(m, {-1, -1}));
vis[0][0] = true;
for (int i = 0; i < int(q.size()); i++) {
auto [x, y] = q[i];
for (auto [dx, dy] : {pair{1, 0}, {0, 1}, {-1, 0}, {0, -1}}) {
int nx = x + dx, ny = y + dy;
if (0 <= nx && nx < n && 0 <= ny && ny < m && !vis[nx][ny] && a[nx][ny] != '#') {
vis[nx][ny] = true;
prv[nx][ny] = {x, y};
q.emplace_back(nx, ny);
}
}
}
if (!vis[n - 1][m - 1]) {
cout << "NIE\n";
return;
}
cout << "TAK\n";
vector<pair<int, int>> path;
for (int x = n - 1, y = m - 1; pair(x, y) != pair(-1, -1); tie(x, y) = prv[x][y]) {
assert(a[x][y] != '#');
path.emplace_back(x, y);
}
reverse(path.begin(), path.end());
string r(n, 'N'), c(m, 'N'), mv;
for (int i = 0; i + 1 < int(path.size()); i++) {
auto [x, y] = path[i];
auto [nx, ny] = path[i + 1];
if (nx - x == 1) {
assert(y == ny);
if (a[nx][ny] != '#') {
if (c[y] == 'T') {
a[nx][ny] ^= 'O' ^ '@';
}
}
if (a[nx][ny] == '@') {
r[nx] = 'T';
}
mv += 'D';
} else if (ny - y == 1) {
assert(x == nx);
if (a[nx][ny] != '#') {
if (r[x] == 'T') {
a[nx][ny] ^= 'O' ^ '@';
}
}
if (a[nx][ny] == '@') {
c[ny] = 'T';
}
mv += 'P';
} else {
assert(false);
}
}
if (a[0][0] == '@') {
if (r[0] == 'N') {
r[0] = 'T';
} else if (c[0] == 'N') {
c[0] = 'T';
} else {
assert(false);
}
}
cout << r << '\n' << c << '\n' << mv << '\n';
};
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
486 4 5 ..#.. @@O@@ ##@#O ..@.@ 2 2 OO OO 2 2 @@ @@ 2 2 @@ #@ 2 2 @O #@ 2 2 @@ OO 2 2 O# @O 2 2 @# #@ 2 2 @. .@ 2 2 @# .O 2 2 OO .O 10 10 @O@O#O@@@# OO#@#@@#OO #@#@#O##O@ OO##@@O#@O O##@@#@O#@ OO@OO@@@O@ @O#@#@O#@O @OOOOO@##. O@OOO##O@@ OO@@OOOO#@ 10 10 @@#OOO#O@@ #@@OO@@.O@ #.O@@O#@@O OO@@#O@#O@ .#...