結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー lloyzlloyz
提出日時 2022-05-21 01:02:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 772 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 57,976 KB
最終ジャッジ日時 2023-10-20 15:22:56
合計ジャッジ時間 5,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
57,976 KB
testcase_01 AC 34 ms
53,584 KB
testcase_02 AC 34 ms
53,584 KB
testcase_03 AC 34 ms
53,584 KB
testcase_04 AC 36 ms
53,584 KB
testcase_05 AC 34 ms
53,584 KB
testcase_06 AC 35 ms
53,584 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 #

from heapq import heappop, heappush

h, w, si, sj = map(int, input().split())
si -= 1
sj -= 1
A = [list(map(int, input().split())) for _ in range(h)]

visited = [[False for _ in range(w)] for _ in range(h)]
visited[si][sj] = True
Heap = []
Directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
curr = A[si][sj]
for di, dj in Directions:
    ni, nj = si + di, sj + dj
    if 0 <= ni < h and 0 <= nj < w:
        heappush(Heap, (A[ni][nj], ni, nj))
while Heap:
    res, ci, cj = heappop(Heap)
    if curr <= res:
        print("No")
        exit()
    curr += res
    visited[ci][cj] = True
    for di, dj in Directions:
        ni, nj = ci + di, cj + dj
        if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
            heappush(Heap, (A[ni][nj], ni, nj))
print("Yes")
0