結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー norioc
提出日時 2022-05-20 22:47:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,313 ms / 3,000 ms
コード長 747 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,012 KB
実行使用メモリ 137,328 KB
最終ジャッジ日時 2024-09-20 09:08:15
合計ジャッジ時間 11,463 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

H, W, Y, X = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(map(int, input().split())))


def delta(row, col):
    for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        r = row + dr
        c = col + dc
        if not (0 <= r < H and 0 <= c < W): continue
        yield r, c


row = Y-1
col = X-1
atk = A[row][col]
q = []
used = {(row, col)}
for r, c in delta(row, col):
    heappush(q, (A[r][c], r, c))
    used.add((r, c))

while q:
    a, row, col = heappop(q)
    if a >= atk:
        print('No')
        break
    atk += a

    for r, c in delta(row, col):
        if (r, c) in used: continue
        heappush(q, (A[r][c], r, c))
        used.add((r, c))
else:
    print('Yes')
0