結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-05-20 21:50:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,017 ms / 3,000 ms
コード長 834 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 100,356 KB
最終ジャッジ日時 2023-10-20 12:22:32
合計ジャッジ時間 9,087 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,572 KB
testcase_01 AC 44 ms
55,572 KB
testcase_02 AC 43 ms
55,572 KB
testcase_03 AC 42 ms
55,572 KB
testcase_04 AC 42 ms
55,572 KB
testcase_05 AC 41 ms
55,572 KB
testcase_06 AC 42 ms
55,572 KB
testcase_07 AC 411 ms
81,128 KB
testcase_08 AC 81 ms
76,628 KB
testcase_09 AC 455 ms
81,472 KB
testcase_10 AC 489 ms
81,464 KB
testcase_11 AC 523 ms
81,712 KB
testcase_12 AC 510 ms
81,852 KB
testcase_13 AC 500 ms
81,664 KB
testcase_14 AC 679 ms
100,356 KB
testcase_15 AC 673 ms
100,356 KB
testcase_16 AC 72 ms
77,080 KB
testcase_17 AC 1,017 ms
96,300 KB
testcase_18 AC 69 ms
77,084 KB
testcase_19 AC 43 ms
55,572 KB
testcase_20 AC 43 ms
55,572 KB
testcase_21 AC 43 ms
55,572 KB
testcase_22 AC 732 ms
90,380 KB
testcase_23 AC 42 ms
55,572 KB
testcase_24 AC 316 ms
81,076 KB
testcase_25 AC 453 ms
81,732 KB
権限があれば一括ダウンロードができます

ソースコード

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