結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ikomaikoma
提出日時 2022-05-20 23:52:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 912 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 216,872 KB
最終ジャッジ日時 2023-10-20 14:48:39
合計ジャッジ時間 6,479 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,352 KB
testcase_01 AC 40 ms
53,352 KB
testcase_02 AC 40 ms
53,352 KB
testcase_03 AC 41 ms
53,352 KB
testcase_04 AC 41 ms
53,352 KB
testcase_05 AC 39 ms
53,352 KB
testcase_06 AC 38 ms
53,352 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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