QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83851#4432. Jungle Trailmagicduck#AC ✓223ms35040kbC++143.0kb2023-03-03 17:28:362023-03-03 17:28:38

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-03 17:28:38]
  • 评测
  • 测评结果:AC
  • 用时:223ms
  • 内存:35040kb
  • [2023-03-03 17:28:36]
  • 提交

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 = n; i >= 1; i--)
            for(int j = m; j >= 1; j--) {
                flag[i][j] = 0;
                if(i == n && j == m) {
                    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;
            }
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 223ms
memory: 35040kb

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
TT
NN
PD
TAK
TN
NT
PD
TAK
TN
NN
DP
TAK
NT
NT
DP
NIE
TAK
TN
NT
DP
TAK
TN
NN
DP
TAK
NN
NN
DP
NIE
TAK
TTNNTTTTNT
NNTTNNTTNN
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