QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149440 | #4432. Jungle Trail | rgnerdplayer# | WA | 291ms | 103720kb | C++20 | 2.7kb | 2023-08-24 16:50:44 | 2023-08-24 16:50:45 |
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 (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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 291ms
memory: 103720kb
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 TN NT PD TAK TT NN PD TAK TN NN DP TAK NT NT DP NIE TAK TN NT DP TAK TN NN DP TAK NN NN DP NIE TAK TNNTNNNNTN NTNNNTNNTT PDDDPPDDDDPPDDPPPP TAK NTTTNTNNNN NTTTNTNTTN DDDDDPDDDPPPPPDPPP TAK NNNTNTTTNT NNTTTTTNNT DDDPPDPDDDDDPPPPPP TAK NNNTNNNTNT NN...
result:
wrong answer you dead (test case 4)