結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー pitP
提出日時 2022-05-21 13:30:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,019 ms / 3,000 ms
コード長 787 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,920 KB
実行使用メモリ 100,620 KB
最終ジャッジ日時 2024-09-20 11:42:14
合計ジャッジ時間 8,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.readline


h,w,y,x = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
y -= 1
x -= 1

visited = [[False]*w for _ in range(h)]

hq = []
now = a[y][x]
visited[y][x] = True

didj = [(1,0),(0,1),(0,-1),(-1,0)]
for di,dj in didj:
    ni = y + di
    nj = x + dj
    if 0 <= ni < h and 0 <= nj < w:
        heapq.heappush(hq,(a[ni][nj] , ni,nj))
        visited[ni][nj] = True

while hq:
    a_nxt,i,j = heapq.heappop(hq)
    if now <= a_nxt:
        print("No")
        exit()
    now += a_nxt
    for di , dj in didj:
        ni = i + di
        nj = j + dj
        if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
            heapq.heappush(hq,(a[ni][nj],ni,nj))
            visited[ni][nj] = True

print("Yes")
0