結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー hir355
提出日時 2022-05-20 22:18:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 894 ms / 3,000 ms
コード長 609 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 100,212 KB
最終ジャッジ日時 2024-09-20 08:31:09
合計ジャッジ時間 8,661 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
dxdy = ((0, 1), (0, -1), (1, 0), (-1, 0))
h, w, x, y = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
d = [[0] * w for _ in range(h)]
d[x - 1][y - 1] = 1
hq = [(a[x - 1][y - 1], x - 1, y - 1)]
t = 0
cnt = 0
while hq:
    p, x, y = heapq.heappop(hq)
    if cnt > 0 and t <= a[x][y]:
        print('No')
        exit(0)
    cnt += 1
    t += a[x][y]
    for dx, dy in dxdy:
        if 0 <= x + dx < h and 0 <= y + dy < w and d[x + dx][y + dy] == 0:
            d[x + dx][y + dy] = 1
            heapq.heappush(hq, (a[x + dx][y + dy], x + dx, y + dy))
print('Yes')
0