QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83847 | #4432. Jungle Trail | magicduck# | TL | 0ms | 0kb | C++14 | 2.6kb | 2023-03-03 17:16:29 | 2023-03-03 17:16:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &F) {
int R = 1; F = 0; char CH = getchar();
for(; !isdigit(CH); CH = getchar()) if(CH == '-') R = -1;
for(; isdigit(CH); CH = getchar()) F = F * 10 + CH - 48;
F *= R;
}
inline void file(string str) {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
const int N = 2e3 + 10;
int ai[N][N], n, m, flag[N][N]; char s[N];
bool check(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= m;
}
int rx[N], ry[N];
void bfs() {
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
flag[i][j] = 0;
if(i == 1 && j == 1) {
flag[i][j] = 1; continue;
}
if(!ai[i][j]) continue;
if(check(i - 1, j) && flag[i - 1][j]) flag[i][j] = 1;
if(check(i, j - 1) && flag[i][j - 1]) flag[i][j] = 1;
}
}
int main() {
//file("");
int T; read(T);
while(T--) {
read(n), read(m);
for(int i = 1; i <= n; i++) {
scanf("%s", s + 1);
for(int j = 1; j <= m; j++) {
if(s[j] == '.') ai[i][j] = 1;
else if(s[j] == 'O') ai[i][j] = 2;
else if(s[j] == '@') ai[i][j] = 3;
else ai[i][j] = 0;
}
}
bfs();
if(!flag[n][m]) {
puts("NIE"); continue;
}
for(int i = 1; i <= n; i++) rx[i] = 0;
for(int i = 1; i <= m; i++) ry[i] = 0;
int x = 1, y = 1, lx = 0, ly = 0; vector<char> R;
while(233) {
if(ai[x][y] >= 2 && (ai[x][y] ^ rx[x] ^ ry[y]) == 3) {
if(lx == x - 1) rx[x] ^= 1;
else ry[y] ^= 1;
}
if(x == n && y == m) break;
int xx = 0, yy = 0;
if(check(x + 1, y) && flag[x + 1][y]) xx = x + 1, yy = y, R.emplace_back('D');
else if(check(x, y + 1) && flag[x][y + 1]) xx = x, yy = y + 1, R.emplace_back('P');
lx = x, ly = y; x = xx, y = yy;
}
puts("TAK");
for(int i = 1; i <= n; i++)
if(rx[i]) putchar('T'); else putchar('N');
puts("");
for(int i = 1; i <= m; i++)
if(ry[i]) putchar('T'); else putchar('N');
puts("");
for(auto i : R) putchar(i); puts("");
}
#ifdef _MagicDuck
fprintf(stderr, "# Time: %.3lf s", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
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@ .#...