QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65139#4432. Jungle TrailSa3tElSefrTL 0ms0kbC++232.1kb2022-11-27 18:24:462022-11-27 18:24:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-27 18:24:48]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-11-27 18:24:46]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double


const int N = 2000 + 5, mod = 998244353;

int n, m;
char grid[N][N];
bool t_rows[N], t_cols[N];
string path;

bool dfs(int r, int c) {
    if (r == n - 1 && c == m - 1) {
        return true;
    }
    if (r + 1 < n && grid[r + 1][c] != '#') {
        if (dfs(r + 1, c)) {
            path += 'D';
            return true;
        }
    }
    if (c + 1 < m && grid[r][c + 1] != '#') {
        if (dfs(r, c + 1)) {
            path += 'P';
            return true;
        }
    }
    return false;
}

void build(int r, int c, int t_r, int t_c, int idx) {
    if (idx == path.size()) {
        return;
    }
    if (path[idx] == 'P') {
        auto n_t_c = t_cols[c + 1] = t_r ^ (grid[r][c + 1] == '@');
        build(r, c + 1, t_r, n_t_c, idx + 1);
    } else {
        auto n_t_r = t_rows[r + 1] = t_c ^ (grid[r + 1][c] == '@');
        build(r + 1, c, n_t_r, t_c, idx + 1);
    }
}

void init() {
    path.clear();
    memset(t_rows, 0, sizeof (t_rows));
    memset(t_cols, 0, sizeof (t_cols));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int z;
    cin >> z;
    while (z--) {
        init();
        cin >> n >> m;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                cin >> grid[i][j];
            }
        }
        if (dfs(0, 0)) {
            reverse(path.begin(), path.end());
            if (grid[0][0] == '@') {
                t_rows[0] = 1;
            }
            build(0, 0, grid[0][0] == '@', 0, 0);
            cout << "TAK\n";
            for (int i = 0; i < n; ++i) {
                cout << (t_rows[i] ? 'T' : 'N');
            }
            cout << '\n';
            for (int i = 0; i < m; ++i) {
                cout << (t_cols[i] ? 'T' : 'N');
            }
            cout << '\n';
            cout << path << '\n';
        } else {
            cout << "NIE\n";
        }
    }
    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@
.#...

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
NNTTTNTTNN
PDDDPPDDDDPPDDPPPP
TAK
NTTTNTNNNN
NTTTNTNTTN
DDDDDPDDDPPPPPDPPP
TAK
NNNTNTTTNT
NNTTTTTNNT
DDDPPDPDDDDDPPPPPP
TAK
NNNTNNNTNT
NN...

result: