結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー hiragnhiragn
提出日時 2022-12-13 23:17:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2024-04-25 06:42:18
合計ジャッジ時間 9,436 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 28 ms
11,008 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 27 ms
11,008 KB
testcase_07 AC 499 ms
21,760 KB
testcase_08 AC 99 ms
22,912 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 557 ms
23,040 KB
testcase_13 AC 494 ms
15,104 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 743 ms
23,680 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 27 ms
11,008 KB
testcase_21 AC 29 ms
11,008 KB
testcase_22 AC 626 ms
22,016 KB
testcase_23 RE -
testcase_24 AC 302 ms
15,104 KB
testcase_25 AC 505 ms
22,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush


def main():
    h, w, sy, sx = map(int, input().split())
    sy -= 1
    sx -= 1
    a = [list(map(int, input().split())) for _ in range(h)]

    used = [[False] * w for _ in range(h)]
    used[sx][sy] = True
    hq = [(a[sx][sy], sx, sy)]
    heapify(hq)
    cur_atk = a[sx][sy]
    dx = [1, 0, -1, 0, 1, -1, -1, 1]
    dy = [0, 1, 0, -1, 1, 1, -1, -1]
    for i in range(4):
        x = sx + dx[i]
        y = sy + dy[i]
        if 0 <= x < h and 0 <= y < w:
            used[x][y] = True
            heappush(hq, (a[x][y], x, y))

    while hq:
        atk, x, y = heappop(hq)
        if cur_atk <= a[x][y]:
            exit(print("No"))

        cur_atk += a[x][y]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < h and 0 <= ny < w and not used[nx][ny]:
                used[nx][ny] = True
                heappush(hq, (a[nx][ny], nx, ny))
    print("Yes")


if __name__ == "__main__":
    main()
0