結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー lloyzlloyz
提出日時 2022-05-21 01:04:53
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,088 ms / 3,000 ms
コード長 811 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 81,580 KB
実行使用メモリ 100,936 KB
最終ジャッジ日時 2023-10-20 15:23:14
合計ジャッジ時間 9,288 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,568 KB
testcase_01 AC 39 ms
53,568 KB
testcase_02 AC 38 ms
53,568 KB
testcase_03 AC 40 ms
53,568 KB
testcase_04 AC 39 ms
53,568 KB
testcase_05 AC 39 ms
53,568 KB
testcase_06 AC 39 ms
53,568 KB
testcase_07 AC 430 ms
80,704 KB
testcase_08 AC 85 ms
78,516 KB
testcase_09 AC 465 ms
80,744 KB
testcase_10 AC 494 ms
80,984 KB
testcase_11 AC 537 ms
81,080 KB
testcase_12 AC 522 ms
81,488 KB
testcase_13 AC 531 ms
81,300 KB
testcase_14 AC 698 ms
100,936 KB
testcase_15 AC 693 ms
100,936 KB
testcase_16 AC 74 ms
76,848 KB
testcase_17 AC 1,088 ms
96,020 KB
testcase_18 AC 74 ms
76,852 KB
testcase_19 AC 39 ms
53,576 KB
testcase_20 AC 40 ms
53,576 KB
testcase_21 AC 40 ms
53,576 KB
testcase_22 AC 743 ms
89,852 KB
testcase_23 AC 40 ms
53,576 KB
testcase_24 AC 325 ms
80,832 KB
testcase_25 AC 472 ms
81,080 KB
権限があれば一括ダウンロードができます

ソースコード

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))
        visited[ni][nj] = True
while Heap:
    res, ci, cj = heappop(Heap)
    if curr <= res:
        print("No")
        exit()
    curr += res
    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))
            visited[ni][nj] = True
print("Yes")
0