結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 👑 KazunKazun
提出日時 2022-05-20 22:05:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,017 ms / 3,000 ms
コード長 715 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 81,748 KB
実行使用メモリ 99,672 KB
最終ジャッジ日時 2023-10-20 12:45:56
合計ジャッジ時間 8,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,404 KB
testcase_01 AC 40 ms
53,404 KB
testcase_02 AC 38 ms
53,404 KB
testcase_03 AC 39 ms
53,404 KB
testcase_04 AC 39 ms
53,404 KB
testcase_05 AC 38 ms
53,404 KB
testcase_06 AC 40 ms
53,404 KB
testcase_07 AC 413 ms
81,356 KB
testcase_08 AC 83 ms
77,688 KB
testcase_09 AC 456 ms
80,708 KB
testcase_10 AC 511 ms
81,160 KB
testcase_11 AC 535 ms
81,460 KB
testcase_12 AC 520 ms
81,268 KB
testcase_13 AC 506 ms
81,424 KB
testcase_14 AC 644 ms
99,672 KB
testcase_15 AC 639 ms
99,672 KB
testcase_16 AC 73 ms
77,868 KB
testcase_17 AC 1,017 ms
95,800 KB
testcase_18 AC 74 ms
77,868 KB
testcase_19 AC 40 ms
53,404 KB
testcase_20 AC 40 ms
53,404 KB
testcase_21 AC 40 ms
53,404 KB
testcase_22 AC 745 ms
90,056 KB
testcase_23 AC 39 ms
53,404 KB
testcase_24 AC 317 ms
81,164 KB
testcase_25 AC 456 ms
80,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

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

A=[[-1]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    for j,a in enumerate(map(int,input().split()),1):
        A[i][j]=a

Q=[]
T=[[0]*(W+2) for _ in range(H+2)]; T[Y][X]=1

dx=[1,0,-1,0]; dy=[0,1,0,-1]
for d in range(4):
    py=Y+dy[d]; px=X+dx[d]
    if A[py][px]!=-1:
        heappush(Q,(A[py][px],py,px))
        T[py][px]=1

remain=H*W-1; attack=A[Y][X]
while Q:
    a,i,j=heappop(Q)
    if attack<=a:
        break

    attack+=a
    remain-=1

    for d in range(4):
        py=i+dy[d]; px=j+dx[d]
        if A[py][px]!=-1 and T[py][px]==0:
            heappush(Q,(A[py][px],py,px))
            T[py][px]=1

print("Yes" if remain==0 else "No")

0