結果

問題 No.1638 Robot Maze
ユーザー kokatsukokatsu
提出日時 2021-10-25 21:04:03
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 214,924 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-04 14:39:33
合計ジャッジ時間 4,203 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,388 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 4 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 5 ms
4,384 KB
testcase_33 AC 6 ms
4,384 KB
testcase_34 AC 6 ms
4,380 KB
testcase_35 AC 6 ms
4,384 KB
testcase_36 AC 7 ms
4,380 KB
testcase_37 AC 5 ms
4,380 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 6 ms
4,380 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 6 ms
4,380 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 6 ms
4,504 KB
testcase_44 AC 6 ms
4,384 KB
testcase_45 AC 6 ms
4,384 KB
testcase_46 AC 5 ms
4,380 KB
testcase_47 AC 5 ms
4,388 KB
testcase_48 AC 6 ms
4,380 KB
testcase_49 AC 5 ms
4,384 KB
testcase_50 AC 6 ms
4,384 KB
testcase_51 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct Grid {
    long x;
    long y;
    long cost;
}

void main() {
    long H, W;
    readf("%d %d\n", H, W);

    long U, D, R, L, K, P;
    readf("%d %d %d %d %d %d\n", U, D, R, L, K, P);

    long xs, ys, xt, yt;
    readf("%d %d %d %d\n", xs, ys, xt, yt);
    --xs, --ys, --xt, --yt;

    auto C = new string[](H);
    foreach (i; 0 .. H) {
        C[i] = readln.chomp;
    }

    auto costs = new long[][](H, W);
    foreach (i; 0 .. H) {
        costs[i][] = long.max;
    }
    costs[xs][ys] = 0;

    auto move = [
        Grid(-1, 0, U),
        Grid(1, 0, D),
        Grid(0, 1, R),
        Grid(0, -1, L)
    ];

    auto que = new BinaryHeap!(Array!Grid, "a.cost > b.cost")();
    que.insert(Grid(xs, ys, 0));

    while (!que.empty) {
        auto f = que.front;
        que.popFront;

        if (costs[f.x][f.y] < f.cost) {
            continue;
        }

        foreach (m; move) {
            auto next = f;
            next.x += m.x, next.y += m.y, next.cost += m.cost;

            if (next.x < 0 || next.x >= H || next.y < 0 || next.y >= W) {
                continue;
            }

            if (C[next.x][next.y] == '#') {
                continue;
            }
            else if (C[next.x][next.y] == '@') {
                next.cost += P;
            }

            if (costs[next.x][next.y] > next.cost) {
                costs[next.x][next.y] = next.cost;
                que.insert(next);
            }
        }
    }

    if (costs[xt][yt] <= K) {
        writeln("Yes");
    }
    else {
        writeln("No");
    }
}
0