QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#355593#4432. Jungle TrailabdelaleemAC ✓92ms70352kbC++141.8kb2024-03-16 22:01:522024-03-16 22:01:52

Judging History

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

  • [2024-03-16 22:01:52]
  • 评测
  • 测评结果:AC
  • 用时:92ms
  • 内存:70352kb
  • [2024-03-16 22:01:52]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
int n, m;
vector<string> v;

bool valid(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m && v[i][j] != '#';
}

vector<vector<int>> mem;

int dp(int i, int j) {
    if (!valid(i, j))return 0;
    if (i == n - 1 && j == m - 1)return 1;
    int &res = mem[i][j];
    if (~res)return res;
    res = dp(i, j + 1);
    if (res)return res;
    res = dp(i + 1, j);
    return res;
}

string r, c, p;

void build(int i, int j) {
    if (i == n - 1 && j == m - 1) {
        return;
    }
    if (dp(i, j + 1)) {
        p += 'P';
        int ps = v[i][j + 1] == '@';
        ps ^= r[i] == 'T';
        if (ps)c[j + 1] = 'T';
        build(i, j + 1);
        return;
    }
    if (dp(i + 1, j)) {
        p += 'D';
        int ps = v[i + 1][j] == '@';
        ps ^= c[j] == 'T';
        if (ps)
            r[i + 1] = 'T';
        build(i + 1, j);
        return;
    }
}

void solve() {
    r.clear();
    c.clear();
    p.clear();
    cin >> n >> m;
    mem = vector<vector<int>>(n, vector<int>(m, -1));
    v = vector<string>(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        r += 'N';
    }
    for (int i = 0; i < m; ++i) {
        c += 'N';
    }
    if (v[0][0] == '@') {
        r[0] = 'T';
    }
    if (dp(0, 0)) {
        build(0, 0);
        cout << "TAK\n";
        cout << r << '\n';
        cout << c << '\n';
        cout << p;
    } else cout << "NIE";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
        if (tc) cout << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 92ms
memory: 70352kb

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
NTNT
NNTNN
PDPPPDD
TAK
NN
NN
PD
TAK
TT
NN
PD
TAK
TT
NN
PD
TAK
TN
NT
PD
TAK
TN
NN
PD
TAK
NT
NT
DP
NIE
TAK
TN
NT
PD
TAK
TN
NN
DP
TAK
NN
NN
PD
NIE
TAK
TTNTTNNNNT
NNNTTNNTTN
PDPPPPPPPDDDDDPDDD
TAK
NNNTTTTNTT
NNTNTNTTNT
PPDDDPPDPDPPDDPDPD
TAK
NNNNTTTNNT
NNNTTNTTNT
PPDDPPPDPDPPDDPDDD
TAK
NTTTNNNTNT
NT...

result:

ok ac (486 test cases)

Extra Test:

score: 0
Extra Test Passed