結果

問題 No.5006 Hidden Maze
ユーザー merom686merom686
提出日時 2022-06-12 14:47:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 3,367 bytes
コンパイル時間 1,932 ms
実行使用メモリ 22,856 KB
スコア 43,912
平均クエリ数 561.88
最終ジャッジ日時 2022-06-12 14:47:21
合計ジャッジ時間 10,211 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
22,612 KB
testcase_01 AC 55 ms
21,892 KB
testcase_02 AC 17 ms
21,892 KB
testcase_03 AC 46 ms
21,780 KB
testcase_04 AC 38 ms
22,588 KB
testcase_05 AC 65 ms
22,856 KB
testcase_06 AC 23 ms
21,992 KB
testcase_07 AC 55 ms
21,952 KB
testcase_08 AC 59 ms
22,456 KB
testcase_09 AC 63 ms
21,952 KB
testcase_10 AC 44 ms
21,928 KB
testcase_11 AC 42 ms
21,880 KB
testcase_12 AC 39 ms
21,892 KB
testcase_13 AC 22 ms
22,276 KB
testcase_14 AC 65 ms
21,940 KB
testcase_15 AC 19 ms
22,004 KB
testcase_16 AC 25 ms
22,004 KB
testcase_17 AC 48 ms
21,780 KB
testcase_18 AC 26 ms
21,904 KB
testcase_19 AC 19 ms
22,576 KB
testcase_20 AC 27 ms
21,904 KB
testcase_21 AC 26 ms
21,940 KB
testcase_22 AC 24 ms
22,276 KB
testcase_23 AC 52 ms
21,880 KB
testcase_24 AC 59 ms
22,588 KB
testcase_25 AC 60 ms
21,928 KB
testcase_26 AC 61 ms
22,252 KB
testcase_27 AC 16 ms
22,620 KB
testcase_28 AC 34 ms
22,016 KB
testcase_29 AC 62 ms
22,132 KB
testcase_30 AC 25 ms
22,564 KB
testcase_31 AC 18 ms
22,016 KB
testcase_32 AC 29 ms
22,216 KB
testcase_33 AC 54 ms
22,252 KB
testcase_34 AC 18 ms
21,928 KB
testcase_35 AC 54 ms
22,600 KB
testcase_36 AC 60 ms
22,576 KB
testcase_37 AC 60 ms
21,940 KB
testcase_38 AC 60 ms
21,892 KB
testcase_39 AC 26 ms
22,204 KB
testcase_40 AC 33 ms
21,904 KB
testcase_41 AC 57 ms
22,576 KB
testcase_42 AC 26 ms
22,108 KB
testcase_43 AC 18 ms
21,780 KB
testcase_44 AC 17 ms
21,940 KB
testcase_45 AC 37 ms
21,892 KB
testcase_46 AC 63 ms
21,808 KB
testcase_47 AC 62 ms
21,928 KB
testcase_48 AC 61 ms
22,004 KB
testcase_49 AC 61 ms
22,600 KB
testcase_50 AC 26 ms
21,940 KB
testcase_51 AC 25 ms
21,904 KB
testcase_52 AC 60 ms
22,828 KB
testcase_53 AC 59 ms
22,704 KB
testcase_54 AC 57 ms
21,992 KB
testcase_55 AC 25 ms
22,004 KB
testcase_56 AC 23 ms
21,916 KB
testcase_57 AC 22 ms
22,228 KB
testcase_58 AC 28 ms
21,940 KB
testcase_59 AC 60 ms
22,216 KB
testcase_60 AC 31 ms
22,204 KB
testcase_61 AC 37 ms
22,004 KB
testcase_62 AC 51 ms
22,716 KB
testcase_63 AC 25 ms
22,588 KB
testcase_64 AC 64 ms
21,940 KB
testcase_65 AC 23 ms
22,576 KB
testcase_66 AC 20 ms
21,880 KB
testcase_67 AC 63 ms
21,952 KB
testcase_68 AC 23 ms
21,916 KB
testcase_69 AC 22 ms
21,892 KB
testcase_70 AC 59 ms
21,756 KB
testcase_71 AC 19 ms
21,916 KB
testcase_72 AC 17 ms
21,892 KB
testcase_73 AC 60 ms
22,444 KB
testcase_74 AC 56 ms
21,904 KB
testcase_75 AC 60 ms
21,904 KB
testcase_76 AC 27 ms
22,692 KB
testcase_77 AC 61 ms
21,940 KB
testcase_78 AC 53 ms
21,940 KB
testcase_79 AC 58 ms
21,756 KB
testcase_80 AC 16 ms
22,004 KB
testcase_81 AC 19 ms
21,780 KB
testcase_82 AC 57 ms
22,600 KB
testcase_83 AC 18 ms
21,904 KB
testcase_84 AC 55 ms
22,004 KB
testcase_85 AC 64 ms
22,620 KB
testcase_86 AC 56 ms
22,264 KB
testcase_87 AC 25 ms
22,276 KB
testcase_88 AC 30 ms
22,600 KB
testcase_89 AC 67 ms
22,608 KB
testcase_90 AC 58 ms
21,892 KB
testcase_91 AC 25 ms
22,608 KB
testcase_92 AC 61 ms
21,992 KB
testcase_93 AC 17 ms
22,264 KB
testcase_94 AC 57 ms
21,952 KB
testcase_95 AC 63 ms
22,576 KB
testcase_96 AC 18 ms
21,780 KB
testcase_97 AC 65 ms
22,456 KB
testcase_98 AC 59 ms
21,952 KB
testcase_99 AC 19 ms
22,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int N = 20;

struct Graph {
    static constexpr ll INF = 1LL << 60;
    struct VertexQ {
        bool operator<(const VertexQ &o) const {
            return c > o.c; // 逆
        }
        int i;
        ll c;
    };
    struct Vertex { int n; int d; ll c; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, -1, INF }), e(m), n(n), m(0) {}
    void add_edge(int a, int b, int c) {
        e[m] = { b, v[a].n, c };
        v[a].n = m;
        m++;
    }
    void dijkstra(int i, int j) {
        for (int i = 0; i < n; i++) v[i].c = INF;
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.i == j) break;
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                ll c = p.c + o.c;
                if (c < v[o.i].c) v[o.i].d = p.i, q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

int c0[N][N];
int c1[N][N];

int main() {
    int h, w, p;
    cin >> h >> w >> p;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            c0[i][j] = c1[i][j] = 10;
        }
    }

    while (1) {
        Graph g(N * N, N * N * 4);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N - 1; j++) {
                int k = i * N + j;
                g.add_edge(k, k + 1, c0[i][j]);
                g.add_edge(k + 1, k, c0[i][j]);
            }
        }
        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j < N; j++) {
                int k = i * N + j;
                g.add_edge(k, k + N, c1[i][j]);
                g.add_edge(k + N, k, c1[i][j]);
            }
        }
        int k = N * N - 1;
        g.dijkstra(0, k);
        string s;
        vector<int> t;
        t.push_back(k);
        while (1) {
            int k1 = g.v[k].d;
            int d = k - k1;
            char x;
            if (d == 1) x = 'R'; else if (d == -1) x = 'L'; else if (d == N) x = 'D'; else x = 'U';
            s.push_back(x);
            t.push_back(k1);
            k = k1;
            if (k == 0) break;
        }
        reverse(s.begin(), s.end());
        reverse(t.begin(), t.end());
        cout << s << endl;

        int a;
        cin >> a;
        if (a == -1) break;

        auto f = [&](int &c, int y) {
            if (y == 0) {
                c = 0;
            } else {
                if (c > 0) c++;
            }
        };

        for (int b = 0; b <= a; b++) {
            int k0 = t[b], k1 = t[b + 1];
            if (k0 > k1) swap(k0, k1);
            int i = k0 / N, j = k0 % N;
            if (abs(k0 - k1) == 1) {
                f(c0[i][j], b == a);
            } else {
                f(c1[i][j], b == a);
            }
        }

        //for (int i = 0; i < N; i++) {
        //    for (int j = 0; j < N - 1; j++) {
        //        cout << c0[i][j] << ' ';
        //    }
        //    cout << '\n';
        //}
        //for (int i = 0; i < N - 1; i++) {
        //    for (int j = 0; j < N; j++) {
        //        cout << c1[i][j] << ' ';
        //    }
        //    cout << '\n';
        //}
    }

    return 0;
}
0