QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#149446 | #4432. Jungle Trail | rgnerdplayer# | AC ✓ | 251ms | 103564kb | C++20 | 2.7kb | 2023-08-24 16:52:43 | 2023-08-24 16:52:46 |
Judging History
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}}) {
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 (path[1] == pair{1, 0}) {
r[0] = 'T';
} else if (path[1] == pair{0, 1}) {
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: 100
Accepted
time: 251ms
memory: 103564kb
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@ .#...
output:
TAK NTNN NNTNT DPPDDPP TAK NN NN DP TAK TT NN DP TAK NN TT PD TAK NT TN PD TAK TN NN DP TAK NT NT DP NIE TAK TN NT DP TAK TN NN DP TAK NN NN DP NIE TAK NNNTNNNNTN TTNNNTNNTT PDDDPPDDDDPPDDPPPP TAK NTTTNTNNNN NTTTNTNTTN DDDDDPDDDPPPPPDPPP TAK NNNTNTTTNT NNTTTTTNNT DDDPPDPDDDDDPPPPPP TAK NNNTNNNTNT NN...
result:
ok ac (486 test cases)
Extra Test:
score: 0
Extra Test Passed