結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー KudeKude
提出日時 2022-05-20 22:33:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 690 ms / 3,000 ms
コード長 691 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 97,568 KB
最終ジャッジ日時 2023-10-20 13:18:35
合計ジャッジ時間 7,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,512 KB
testcase_01 AC 38 ms
53,512 KB
testcase_02 AC 38 ms
53,512 KB
testcase_03 AC 39 ms
53,512 KB
testcase_04 AC 38 ms
53,512 KB
testcase_05 AC 38 ms
53,512 KB
testcase_06 AC 39 ms
53,512 KB
testcase_07 AC 350 ms
81,628 KB
testcase_08 AC 80 ms
76,288 KB
testcase_09 AC 345 ms
82,060 KB
testcase_10 AC 392 ms
82,364 KB
testcase_11 AC 419 ms
82,280 KB
testcase_12 AC 411 ms
82,524 KB
testcase_13 AC 407 ms
82,480 KB
testcase_14 AC 434 ms
97,552 KB
testcase_15 AC 429 ms
97,568 KB
testcase_16 AC 71 ms
76,740 KB
testcase_17 AC 690 ms
94,496 KB
testcase_18 AC 72 ms
76,736 KB
testcase_19 AC 38 ms
53,512 KB
testcase_20 AC 40 ms
53,512 KB
testcase_21 AC 40 ms
53,512 KB
testcase_22 AC 639 ms
91,532 KB
testcase_23 AC 39 ms
53,512 KB
testcase_24 AC 304 ms
81,716 KB
testcase_25 AC 323 ms
81,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
h, w, x, y = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
x -= 1
y -= 1
dis = [1, 0, -1, 0]
djs = [0, 1, 0, -1]
added = [[False] * w for _ in range(h)]
added[x][y] = True

q = []

def add_neighbor(i, j):
    for di, dj in zip(dis, djs):
        ni = i + di
        nj = j + dj
        if 0 <= ni < h and 0 <= nj < w and not added[ni][nj]:
            added[ni][nj] = True
            heappush(q, (a[ni][nj], (ni, nj)))

now = a[x][y]
added[x][y] = True
add_neighbor(x, y)

while q:
    v, (i, j) = heappop(q)
    if v >= now:
        print('No')
        break
    now += v
    add_neighbor(i, j)
else:
    print('Yes')
0