結果

問題 No.1638 Robot Maze
ユーザー kokatsukokatsu
提出日時 2021-10-25 20:15:02
言語 D
(dmd 2.109.1)
結果
RE  
実行時間 -
コード長 1,511 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 220,652 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 12:57:54
合計ジャッジ時間 3,531 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 WA * 2 RE * 4
権限があれば一括ダウンロードができます

ソースコード

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