結果

問題 No.1638 Robot Maze
ユーザー kokatsukokatsu
提出日時 2021-10-25 20:15:02
言語 D
(dmd 2.107.1)
結果
RE  
実行時間 -
コード長 1,511 bytes
コンパイル時間 3,137 ms
コンパイル使用メモリ 216,604 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 14:38:45
合計ジャッジ時間 5,096 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std;

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

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

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

    int 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 int[][](H, W);
    foreach (i; 0 .. H) {
        costs[i][] = int.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;

        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) {
                continue;
            }

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

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