QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138940#4432. Jungle Trailckiseki#AC ✓65ms23144kbC++172.6kb2023-08-12 14:41:022023-08-12 14:41:06

Judging History

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

  • [2023-08-12 14:41:06]
  • 评测
  • 测评结果:AC
  • 用时:65ms
  • 内存:23144kb
  • [2023-08-12 14:41:02]
  • 提交

answer

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

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

constexpr int kInf = 1 << 30;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        vector<string> a(n);
        for (auto &ai : a)
            cin >> ai;
        auto d = vector(n, vector(m, kInf));
        d[0][0] = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (i == 0 and j == 0)
                    continue;
                if (a[i][j] == '#')
                    continue;
                if (i) d[i][j] = min(d[i][j], d[i - 1][j] + 1);
                if (j) d[i][j] = min(d[i][j], d[i][j - 1] + 1);
            }
        }
        if (d[n - 1][m - 1] == kInf) {
            cout << "NIE\n";
            continue;
        }

        auto bad = [](char x, char y) {
            if (x == '@' and y == 'N')
                return true;
            if (x == 'O' and y == 'T')
                return true;
            return false;
        };

        string ans;
        {
            int x = n - 1, y = m - 1;
            while (x != 0 or y != 0) {
                if (x and d[x][y] == d[x - 1][y] + 1) {
                    ans += "D";
                    --x;
                } else {
                    ans += "P";
                    --y;
                }
            }
        }
        reverse(ans.begin(), ans.end());
        string hori(n, 'N'), vert(m, 'N');
        if (a[0][0] == '@') hori[0] = 'T';
        int x = 0, y = 0;
        for (auto c : ans) {
            if (c == 'D') {
                x++;
                if (bad(a[x][y], vert[y])) {
                    hori[x] = 'T';
                }
            } else {
                y++;
                if (bad(a[x][y], hori[x])) {
                    vert[y] = 'T';
                }
            }
        }
        cout << "TAK\n";
        cout << hori << '\n';
        cout << vert << '\n';
        cout << ans << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 65ms
memory: 23144kb

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
TT
NN
PD
TAK
TN
NN
DP
TAK
NN
NN
PD
NIE
TAK
TTNTTNNNNT
NNNTTNNNTN
PDPPPPPPPDDDDDPDDD
TAK
NNNTTTNTNN
NNTNTNTNTN
PPDDDPPDPDPPDDPDPD
TAK
NNNNTTTTTN
NNNTTNTTNN
PPDDPPPDPDPPDDPDDD
TAK
NTTTNNNTNT
NT...

result:

ok ac (486 test cases)

Extra Test:

score: 0
Extra Test Passed