結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 👑 SPD_9X2
提出日時 2022-05-20 21:49:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 833 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 101,996 KB
最終ジャッジ日時 2024-09-20 07:51:29
合計ジャッジ時間 9,547 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin
from collections import deque
import heapq

H,W,X,Y = map(int,stdin.readline().split())

X -= 1
Y -= 1

A = [ list(map(int,stdin.readline().split())) for i in range(H) ]

dp = [[True] * W for i in range(H)]

q = deque()

now = A[X][Y]
dp[X][Y] = False

q = []

for i,j in ( (X-1,Y),(X+1,Y),(X,Y-1),(X,Y+1) ):

    if 0 <= i < H and 0 <= j < W:
        dp[i][j] = False
        heapq.heappush( q,(A[i][j] , i,j) )


while q:

    cost,x,y = heapq.heappop(q)
    #print (now,cost,x,y)

    if cost > now:
        print ("No")
        sys.exit()
    
    now += cost
    
    for i,j in ( (x-1,y),(x+1,y),(x,y-1),(x,y+1) ):

        if 0 <= i < H and 0 <= j < W and dp[i][j]:
            dp[i][j] = False
            heapq.heappush( q,(A[i][j] , i,j) )

    #print (now,q)
    
print ("Yes")
0