結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー titia
提出日時 2022-05-20 21:31:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 101,504 KB
最終ジャッジ日時 2024-09-20 07:22:24
合計ジャッジ時間 8,652 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import heapq

H,W,x,y=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]

x-=1
y-=1
NOW=A[x][y]

B=0
USE=[[0]*W for i in range(H)]

USE[0][0]=1

Q=[]

for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
    if 0<=z<H and 0<=w<W:
        heapq.heappush(Q,(A[z][w],z,w))
        USE[z][w]=1

while Q:
    if Q[0][0]<NOW:
        p,x,y=heapq.heappop(Q)
        NOW+=p
        USE[x][y]=1

        for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
            if 0<=z<H and 0<=w<W and USE[z][w]==0:
                heapq.heappush(Q,(A[z][w],z,w))
                USE[z][w]=1

    else:
        print("No")
        exit()

print("Yes")
        
    
    
0