結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 👑 H20H20
提出日時 2022-04-10 19:31:58
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 758 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 102,792 KB
最終ジャッジ日時 2023-09-09 03:33:40
合計ジャッジ時間 9,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,364 KB
testcase_01 AC 74 ms
71,072 KB
testcase_02 AC 75 ms
71,376 KB
testcase_03 AC 75 ms
71,212 KB
testcase_04 AC 74 ms
71,160 KB
testcase_05 AC 74 ms
71,464 KB
testcase_06 WA -
testcase_07 AC 430 ms
82,536 KB
testcase_08 WA -
testcase_09 AC 483 ms
82,500 KB
testcase_10 WA -
testcase_11 AC 558 ms
83,188 KB
testcase_12 AC 546 ms
83,624 KB
testcase_13 AC 108 ms
78,256 KB
testcase_14 AC 678 ms
102,704 KB
testcase_15 AC 681 ms
102,792 KB
testcase_16 AC 109 ms
78,056 KB
testcase_17 AC 1,082 ms
97,820 KB
testcase_18 AC 110 ms
78,220 KB
testcase_19 AC 76 ms
71,160 KB
testcase_20 WA -
testcase_21 AC 76 ms
71,252 KB
testcase_22 AC 765 ms
91,436 KB
testcase_23 AC 75 ms
71,364 KB
testcase_24 AC 353 ms
82,792 KB
testcase_25 AC 472 ms
83,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

H,W,Y,X = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(map(int, input().split())))

if not(1<=H<=500 and 1<=W<=500 and len(A)==H and 1<=Y<=H and 1<=X<=W):
    exit()
for a in A:
    if not (len(a)==W and 1<=min(a) and max(a)<=10**9):
        exit()


T = [[0]*W for _ in range(H)]
H,W,Y,X=H-1,W-1,Y-1,X-1
heap = []
T[Y][X]=1
V = A[Y][X]
A[Y][X]=0
heapq.heappush(heap,(A[Y][X],Y,X))

HI = [1,0,-1,0]
WI = [0,1,0,-1]
while len(heap):
    v,h,w = heapq.heappop(heap)
    if V<=v:
        print('No')
        exit()
    V+=v
    for i in range(4):
        nh=h+HI[i]
        nw=w+WI[i]
        if 0<=nh<H and 0<=nw<W and T[nh][nw]==0:
            T[nh][nw]=1
            heapq.heappush(heap,(A[nh][nw],nh,nw))
print('Yes')
0