結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ikoma
提出日時 2022-05-20 23:52:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 912 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 263,392 KB
最終ジャッジ日時 2024-09-20 10:17:53
合計ジャッジ時間 5,363 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappush,heappop,heapify,heappushpop
from heapq import *
from heapq import _heappop_max,_heapify_max,_siftdown_max
heappop_max = _heappop_max;heapify_max = _heapify_max
def heappush_max(heap:list,item): heap.append(item); _siftdown_max(heap, 0, len(heap)-1)

H,W,Y,X=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
INF=float("inf")
dp = [[0]*W for _ in range(H)]
dp[Y-1][X-1]=A[Y-1][X-1]
A[Y-1][X-1]=0
que = [(dp[Y-1][X-1],Y-1,X-1)]
while que:
    a,y,x=heappop_max(que)
    A[y][x]=0
    for ny,nx in [(y-1,x),(y+1,x),(y,x-1),(y,x+1)]:
        if 0<=ny<H and 0<=nx<W and A[ny][nx]<a:
            if dp[ny][nx]<a+A[ny][nx]:
                dp[ny][nx]=a+A[ny][nx]
                heappush_max(que,(dp[ny][nx],ny,nx))

for y in range(H):
    if any([a!=0 for a in A[y]]):
        print("No")
        break
else:
    print("Yes")
0