結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー kokatsukokatsu
提出日時 2022-10-25 00:32:19
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,109 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 218,280 KB
実行使用メモリ 17,912 KB
最終ジャッジ日時 2023-09-04 18:41:59
合計ジャッジ時間 5,898 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 131 ms
12,424 KB
testcase_08 WA -
testcase_09 AC 183 ms
16,264 KB
testcase_10 AC 183 ms
16,748 KB
testcase_11 AC 178 ms
15,232 KB
testcase_12 AC 162 ms
13,668 KB
testcase_13 AC 151 ms
14,440 KB
testcase_14 WA -
testcase_15 AC 142 ms
15,372 KB
testcase_16 AC 27 ms
11,720 KB
testcase_17 AC 218 ms
15,060 KB
testcase_18 AC 26 ms
12,432 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,388 KB
testcase_22 AC 168 ms
13,728 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 87 ms
13,776 KB
testcase_25 AC 148 ms
13,216 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