結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー kokatsukokatsu
提出日時 2022-10-25 00:33:18
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 214 ms / 3,000 ms
コード長 1,110 bytes
コンパイル時間 3,237 ms
コンパイル使用メモリ 218,332 KB
実行使用メモリ 16,828 KB
最終ジャッジ日時 2023-09-04 18:42:20
合計ジャッジ時間 6,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,508 KB
testcase_07 AC 131 ms
11,644 KB
testcase_08 AC 54 ms
14,992 KB
testcase_09 AC 180 ms
16,048 KB
testcase_10 AC 182 ms
16,828 KB
testcase_11 AC 175 ms
14,716 KB
testcase_12 AC 160 ms
14,512 KB
testcase_13 AC 151 ms
15,724 KB
testcase_14 AC 141 ms
15,656 KB
testcase_15 AC 141 ms
16,092 KB
testcase_16 AC 25 ms
12,156 KB
testcase_17 AC 214 ms
14,524 KB
testcase_18 AC 26 ms
12,664 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 166 ms
13,060 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 87 ms
14,464 KB
testcase_25 AC 143 ms
13,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct Square {
    long y, x, a;
}

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

    auto A = new long[][](H);
    foreach (i; 0 .. H) A[i] = readln.chomp.split.to!(long[]);

    --Y, --X;

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

    auto seen = new bool[][](H, W);
    seen[Y][X] = true;

    long S = A[Y][X];

    auto heap = new BinaryHeap!(Array!Square, "a.a > b.a")();
    foreach (i; 0 .. 4) {
        long ny = Y + dy[i], nx = X + dx[i];
        if (0 <= ny && ny < H && 0 <= nx && nx < W) {
            heap.insert(Square(ny, nx, A[ny][nx]));
            seen[ny][nx] = true;
        }
    }

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

        if (S <= f.a) break;

        heap.popFront;
        S += f.a;

        foreach (i; 0 .. 4) {
            long ny = f.y + dy[i], nx = f.x + dx[i];
            if (0 <= ny && ny < H && 0 <= nx && nx < W && !seen[ny][nx]) {
                heap.insert(Square(ny, nx, A[ny][nx]));
                seen[ny][nx] = true;
            }
        }
    }

    writeln(heap.empty ? "Yes" : "No");
}
0