QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64638#4432. Jungle TrailAs3b_team_f_masrWA 1570ms294416kbC++5.6kb2022-11-25 04:55:432022-11-25 04:55:46

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-25 04:55:46]
  • 评测
  • 测评结果:WA
  • 用时:1570ms
  • 内存:294416kb
  • [2022-11-25 04:55:43]
  • 提交

answer

#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;
using namespace std;
int di[] = {1, 0, -1, -1, 0, 1, -1, 1};
int dj[] = {1, 1, 0, -1, -1, 0, 1, -1};
const ll oo = 1e18, MOD = 998244353;
const int N = 2005, M = 1e6 + 5;
const ld PI = acos(-1.0), EPS = 1e-9;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int t, n, m, vis[N][N][2][2][2][2], id;
char rows[N], cols[N], path[N], a[N][N];
bool dp[N][N][2][2][2][2];

bool solve(int i, int j, int doner, int donec, int snaker, int snakec) {
    bool &ret = dp[i][j][doner][donec][snaker][snakec];
    if (i == n - 1 && j == m - 1) return ret = 1;
    if (vis[i][j][doner][donec][snaker][snakec] == id) return ret;
    vis[i][j][doner][donec][snaker][snakec] = id;
    ret = 0;
    if (i != n - 1 && a[i + 1][j] != '#') {
        if (a[i + 1][j] == '.' || (a[i + 1][j] == 'O' && !donec) || (a[i + 1][j] == '@' && donec))
            ret |= solve(i + 1, j, 0, donec, a[i + 1][j] == 'O', snakec | (a[i + 1][j] == 'O'));
        if (a[i + 1][j] == '@' && !donec) ret |= solve(i + 1, j, 1, 0, 0, snakec);
        if (a[i + 1][j] == '@' && !donec && !snakec) ret |= solve(i + 1, j, 0, 1, 0, 0);
        if (a[i + 1][j] == 'O' && donec) ret |= solve(i + 1, j, 1, 1, 1, 1);
    }
    if (j != m - 1 && a[i][j + 1] != '#') {
        if (a[i][j + 1] == '.' || (a[i][j + 1] == 'O' && !doner) || (a[i][j + 1] == '@' && doner))
            ret |= solve(i, j + 1, doner, 0, snaker | (a[i][j + 1] == 'O'), a[i][j + 1] == 'O');
        if (a[i][j + 1] == '@' && !doner) ret |= solve(i, j + 1, 0, 1, snaker, 0);
        if (a[i][j + 1] == '@' && !doner && !snaker) ret |= solve(i, j + 1, 1, 0, 0, 0);
        if (a[i][j + 1] == 'O' && doner) ret |= solve(i, j + 1, 1, 1, 1, 1);
    }
    return ret;
}

void build(int i, int j, int doner, int donec, int snaker, int snakec) {
    if (i == n - 1 && j == m - 1) return;
    if (i != n - 1 && a[i + 1][j] != '#') {
        if (a[i + 1][j] == '.' || (a[i + 1][j] == 'O' && !donec) || (a[i + 1][j] == '@' && donec)) {
            if (dp[i + 1][j][0][donec][a[i + 1][j] == 'O'][snakec | (a[i + 1][j] == 'O')]) {
                path[i + j] = 'D';
                build(i + 1, j, 0, donec, a[i + 1][j] == 'O', snakec | (a[i + 1][j] == 'O'));
                return;
            }
        }
        if (a[i + 1][j] == '@' && !donec) {
            if (dp[i + 1][j][1][0][0][snakec]) {
                path[i + j] = 'D', rows[i + 1] = 'T';
                build(i + 1, j, 1, 0, 0, snakec);
                return;
            }
        }
        if (a[i + 1][j] == '@' && !donec && !snakec) {
            if (dp[i + 1][j][0][1][0][0]) {
                path[i + j] = 'D', cols[j] = 'T';
                build(i + 1, j, 0, 1, 0, 0);
                return;
            }
        }
        if (a[i + 1][j] == 'O' && donec) {
            if (dp[i + 1][j][1][1][1][1]) {
                path[i + j] = 'D', rows[i + 1] = 'T';
                build(i + 1, j, 1, 1, 1, 1);
                return;
            }
        }
    }
    if (j != m - 1 && a[i][j + 1] != '#') {
        if (a[i][j + 1] == '.' || (a[i][j + 1] == 'O' && !doner) || (a[i][j + 1] == '@' && doner)) {
            if (dp[i][j + 1][doner][0][snaker | (a[i][j + 1] == 'O')][a[i][j + 1] == 'O']) {
                path[i + j] = 'P';
                build(i, j + 1, doner, 0, snaker | (a[i][j + 1] == 'O'), a[i][j + 1] == 'O');
                return;
            }
        }
        if (a[i][j + 1] == '@' && !doner) {
            if (dp[i][j + 1][0][1][snaker][0]) {
                path[i + j] = 'P', cols[j + 1] = 'T';
                build(i, j + 1, 0, 1, snaker, 0);
                return;
            }
        }
        if (a[i][j + 1] == '@' && !doner && !snaker) {
            if (dp[i][j + 1][1][0][0][0]) {
                path[i + j] = 'P', rows[i] = 'T';
                build(i, j + 1, 1, 0, 0, 0);
                return;
            }
        }
        if (a[i][j + 1] == 'O' && doner) {
            if (dp[i][j + 1][1][1][1][1]) {
                path[i + j] = 'P', cols[j + 1] = 'T';
                build(i, j + 1, 1, 1, 1, 1);
                return;
            }
        }
    }
}

#define endl '\n'
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("farm.in", "r", stdin);
    //memset(dp, -1, sizeof dp);
    cin >> t;
    while (t--) {
        id++;
        cin >> n >> m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) cin >> a[i][j];
        }
        bool no = 0;
        for (int i = 0; i < n; i++) rows[i] = 'N';
        for (int i = 0; i < m; i++) cols[i] = 'N';
        if (solve(0, 0, 0, 0, a[0][0] == 'O', a[0][0] == 'O') && a[0][0] != '#' && a[0][0] != '@')
            build(0, 0, 0, 0, a[0][0] == 'O', a[0][0] == 'O');
        else if (a[0][0] == '@' && solve(0, 0, 1, 0, 0, 0))
            build(0, 0, 1, 0, 0, 0), rows[0] = 'T';
        else if (a[0][0] == '@' && solve(0, 0, 0, 1, 0, 0))
            build(0, 0, 0, 1, 0, 0), cols[0] = 'T';
        else no = 1;
        if (no) cout << "NIE" << endl;
        else {
            cout << "TAK" << endl;
            for (int i = 0; i < n; i++) cout << rows[i];
            cout << endl;
            for (int i = 0; i < m; i++) cout << cols[i];
            cout << endl;
            for (int i = 0; i < n + m - 2; i++) cout << path[i];
            cout << endl;
        }
    }

    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1570ms
memory: 294416kb

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:

wrong answer Token "DPPPPPDPPPPPPPPPDPPDPPPDDPPPPP...PPPDPPPPPPPPPTNTTTNTTTNTNNTTNNT" doesn't correspond to pattern "[TN]*" (test case 441)