結果

問題 No.1949 足し算するだけのパズルゲーム(2)
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2022-05-20 21:49:19
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 833 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 374 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 107,164 KB
最終ジャッジ日時 2026-04-08 19:35:36
合計ジャッジ時間 7,055 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""

"""

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