結果

問題 No.424 立体迷路
ユーザー kokatsukokatsu
提出日時 2023-01-12 21:46:37
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 2,454 ms
コンパイル使用メモリ 203,800 KB
実行使用メモリ 4,464 KB
最終ジャッジ日時 2023-09-04 19:36:48
合計ジャッジ時間 3,962 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 3 ms
4,464 KB
testcase_25 AC 2 ms
4,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int h, w, sx, sy, gx, gy;
    readf("%d %d\n%d %d %d %d\n", h, w, sx, sy, gx, gy);

    auto b = new string[](h);
    foreach (i; 0 .. h) readf("%s\n", b[i]);

    --sx, --sy, --gx, --gy;

    int[] dx = [-1, 0, 1, 0], dy = [0, 1, 0, -1];

    auto reach = new bool[][](h, w);
    reach[sx][sy] = true;

    void f(int x, int y) {
        foreach (i; 0 .. 4) {
            int x1 = x + dx[i], y1 = y + dy[i];
            if (0 <= x1 && x1 < h && 0 <= y1 && y1 < w
                && abs(b[x][y]-b[x1][y1]) <= 1 && !reach[x1][y1]) {
                reach[x1][y1] = true;
                f(x1, y1);
            }

            int x2 = x + dx[i] * 2, y2 = y + dy[i] * 2;
            if (0 <= x2 && x2 < h && 0 <= y2 && y2 < w
                && b[x][y] == b[x2][y2] && b[x][y] > b[x1][y1] && !reach[x2][y2]) {
                reach[x2][y2] = true;
                f(x2, y2);
            }
        }
    }

    f(sx, sy);

    writeln(reach[gx][gy] ? "YES" : "NO");
}
0