結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
kokatsu
|
| 提出日時 | 2021-10-25 21:04:03 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,572 bytes |
| コンパイル時間 | 2,554 ms |
| コンパイル使用メモリ | 219,380 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 12:58:56 |
| 合計ジャッジ時間 | 4,523 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
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");
}
}
kokatsu