結果

問題 No.5006 Hidden Maze
ユーザー merom686merom686
提出日時 2022-06-12 15:25:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 3,560 bytes
コンパイル時間 1,887 ms
実行使用メモリ 22,864 KB
スコア 76,032
平均クエリ数 240.68
最終ジャッジ日時 2022-06-12 15:26:13
合計ジャッジ時間 9,943 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
21,892 KB
testcase_01 AC 31 ms
21,916 KB
testcase_02 AC 21 ms
21,880 KB
testcase_03 AC 20 ms
22,204 KB
testcase_04 AC 30 ms
21,892 KB
testcase_05 AC 50 ms
21,928 KB
testcase_06 AC 27 ms
22,420 KB
testcase_07 AC 94 ms
22,444 KB
testcase_08 AC 93 ms
21,940 KB
testcase_09 AC 76 ms
21,880 KB
testcase_10 AC 23 ms
21,940 KB
testcase_11 AC 20 ms
21,916 KB
testcase_12 AC 23 ms
22,704 KB
testcase_13 AC 27 ms
22,564 KB
testcase_14 AC 33 ms
22,228 KB
testcase_15 AC 17 ms
22,716 KB
testcase_16 AC 27 ms
22,564 KB
testcase_17 AC 20 ms
22,564 KB
testcase_18 AC 27 ms
21,904 KB
testcase_19 AC 24 ms
21,756 KB
testcase_20 AC 21 ms
21,928 KB
testcase_21 AC 29 ms
21,940 KB
testcase_22 AC 21 ms
21,940 KB
testcase_23 AC 20 ms
22,540 KB
testcase_24 AC 35 ms
21,904 KB
testcase_25 AC 31 ms
22,252 KB
testcase_26 AC 96 ms
22,588 KB
testcase_27 AC 36 ms
22,516 KB
testcase_28 AC 21 ms
21,928 KB
testcase_29 AC 29 ms
22,600 KB
testcase_30 AC 22 ms
21,744 KB
testcase_31 AC 22 ms
22,576 KB
testcase_32 AC 22 ms
21,940 KB
testcase_33 AC 32 ms
22,844 KB
testcase_34 AC 19 ms
22,204 KB
testcase_35 AC 27 ms
21,968 KB
testcase_36 AC 41 ms
21,992 KB
testcase_37 AC 38 ms
21,980 KB
testcase_38 AC 51 ms
21,780 KB
testcase_39 AC 33 ms
21,756 KB
testcase_40 AC 19 ms
21,780 KB
testcase_41 AC 24 ms
21,928 KB
testcase_42 AC 21 ms
22,576 KB
testcase_43 AC 58 ms
22,864 KB
testcase_44 AC 22 ms
22,600 KB
testcase_45 AC 28 ms
22,252 KB
testcase_46 AC 66 ms
21,992 KB
testcase_47 AC 23 ms
21,808 KB
testcase_48 AC 88 ms
21,768 KB
testcase_49 AC 54 ms
22,588 KB
testcase_50 AC 21 ms
22,612 KB
testcase_51 AC 22 ms
21,904 KB
testcase_52 AC 27 ms
21,812 KB
testcase_53 AC 46 ms
21,768 KB
testcase_54 AC 35 ms
21,780 KB
testcase_55 AC 34 ms
21,892 KB
testcase_56 AC 31 ms
22,444 KB
testcase_57 AC 54 ms
21,892 KB
testcase_58 AC 42 ms
22,252 KB
testcase_59 AC 27 ms
21,768 KB
testcase_60 AC 21 ms
21,892 KB
testcase_61 AC 19 ms
22,228 KB
testcase_62 AC 24 ms
21,780 KB
testcase_63 AC 23 ms
21,768 KB
testcase_64 AC 30 ms
21,968 KB
testcase_65 AC 91 ms
22,204 KB
testcase_66 AC 21 ms
21,868 KB
testcase_67 AC 54 ms
22,716 KB
testcase_68 AC 23 ms
22,216 KB
testcase_69 AC 50 ms
22,632 KB
testcase_70 AC 21 ms
21,780 KB
testcase_71 AC 23 ms
21,992 KB
testcase_72 AC 24 ms
21,952 KB
testcase_73 AC 31 ms
21,928 KB
testcase_74 AC 44 ms
21,928 KB
testcase_75 AC 39 ms
22,204 KB
testcase_76 AC 35 ms
21,904 KB
testcase_77 AC 89 ms
21,768 KB
testcase_78 AC 37 ms
22,228 KB
testcase_79 AC 70 ms
21,928 KB
testcase_80 AC 21 ms
22,596 KB
testcase_81 AC 23 ms
21,880 KB
testcase_82 AC 24 ms
21,928 KB
testcase_83 AC 22 ms
22,004 KB
testcase_84 AC 25 ms
22,540 KB
testcase_85 AC 37 ms
21,892 KB
testcase_86 AC 20 ms
21,992 KB
testcase_87 AC 24 ms
22,456 KB
testcase_88 AC 56 ms
21,992 KB
testcase_89 AC 94 ms
21,868 KB
testcase_90 AC 22 ms
21,756 KB
testcase_91 AC 20 ms
22,576 KB
testcase_92 AC 25 ms
21,768 KB
testcase_93 AC 24 ms
22,264 KB
testcase_94 AC 21 ms
22,456 KB
testcase_95 AC 71 ms
22,216 KB
testcase_96 AC 18 ms
22,192 KB
testcase_97 AC 87 ms
22,216 KB
testcase_98 AC 91 ms
21,928 KB
testcase_99 AC 46 ms
21,916 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;
};

double c0[N][N];
double 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] = 0.2;
        }
    }

    while (1) {
        auto u = [&](double t) {
            t = 1 - t;
            t = -log(t) * 1e6;
            return (int)clamp(t, 0.0, 1e9);
        };

        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, u(c0[i][j]));
                g.add_edge(k + 1, k, u(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, u(c1[i][j]));
                g.add_edge(k + N, k, u(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 = [&](double &c, int y) {
            if (y == 0) {
                c = 0;
            } else {
                if (c > 0) c = c / ((1 - c) * p / 100 + 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