結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー rlangevinrlangevin
提出日時 2023-01-21 19:23:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,365 ms / 3,000 ms
コード長 778 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 137,096 KB
最終ジャッジ日時 2023-09-06 07:28:55
合計ジャッジ時間 13,269 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,504 KB
testcase_01 AC 76 ms
71,236 KB
testcase_02 AC 76 ms
71,548 KB
testcase_03 AC 75 ms
71,372 KB
testcase_04 AC 75 ms
71,272 KB
testcase_05 AC 76 ms
71,316 KB
testcase_06 AC 75 ms
71,276 KB
testcase_07 AC 658 ms
115,660 KB
testcase_08 AC 115 ms
78,340 KB
testcase_09 AC 694 ms
116,128 KB
testcase_10 AC 733 ms
117,752 KB
testcase_11 AC 775 ms
119,360 KB
testcase_12 AC 752 ms
119,580 KB
testcase_13 AC 771 ms
118,672 KB
testcase_14 AC 835 ms
136,996 KB
testcase_15 AC 839 ms
137,096 KB
testcase_16 AC 100 ms
77,992 KB
testcase_17 AC 1,365 ms
132,892 KB
testcase_18 AC 104 ms
77,988 KB
testcase_19 AC 74 ms
71,556 KB
testcase_20 AC 75 ms
71,348 KB
testcase_21 AC 77 ms
71,472 KB
testcase_22 AC 995 ms
127,428 KB
testcase_23 AC 75 ms
71,512 KB
testcase_24 AC 447 ms
96,088 KB
testcase_25 AC 662 ms
115,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

H, W, X, Y = map(int, input().split())
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
    
S = set()
X, Y = X - 1, Y - 1
S.add((X, Y))
Q = []
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for k in range(4):
    x = X + dx[k]
    y = Y + dy[k]
    if x < 0 or x > H - 1 or y < 0 or y > W - 1:
        continue
    heappush(Q, (A[x][y], x, y))
    S.add((x, y))

now = A[X][Y]
while Q:
    v, px, py = heappop(Q)
    if v >= now:
        print("No")
        exit()
    now += v
    
    for k in range(4):
        x = px + dx[k]
        y = py + dy[k]
        if x < 0 or x > H - 1 or y < 0 or y > W - 1:
            continue
        if (x, y) in S:
            continue
        S.add((x, y))
        heappush(Q, (A[x][y], x, y))
print("Yes")
0