結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー gr1msl3ygr1msl3y
提出日時 2022-05-22 22:49:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,089 ms / 3,000 ms
コード長 634 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 100,928 KB
最終ジャッジ日時 2023-10-20 17:21:46
合計ジャッジ時間 9,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,568 KB
testcase_01 AC 38 ms
53,568 KB
testcase_02 AC 38 ms
53,568 KB
testcase_03 AC 38 ms
53,568 KB
testcase_04 AC 38 ms
53,568 KB
testcase_05 AC 38 ms
53,568 KB
testcase_06 AC 38 ms
53,568 KB
testcase_07 AC 417 ms
80,736 KB
testcase_08 AC 79 ms
76,288 KB
testcase_09 AC 456 ms
80,772 KB
testcase_10 AC 500 ms
80,912 KB
testcase_11 AC 528 ms
81,112 KB
testcase_12 AC 517 ms
81,468 KB
testcase_13 AC 510 ms
81,340 KB
testcase_14 AC 670 ms
100,928 KB
testcase_15 AC 667 ms
100,928 KB
testcase_16 AC 71 ms
76,768 KB
testcase_17 AC 1,089 ms
96,104 KB
testcase_18 AC 72 ms
76,772 KB
testcase_19 AC 39 ms
53,572 KB
testcase_20 AC 40 ms
53,572 KB
testcase_21 AC 40 ms
53,572 KB
testcase_22 AC 717 ms
89,804 KB
testcase_23 AC 39 ms
53,572 KB
testcase_24 AC 328 ms
80,868 KB
testcase_25 AC 447 ms
81,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq as hq
H, W, Y, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Y -= 1
X -= 1
seen = [[0]*W for _ in range(H)]
seen[Y][X] = 1
v = A[Y][X]
A[Y][X] = 0
ct = 0

mv = [[1, 0], [0, 1], [-1, 0], [0, -1]]
task = [(0, Y, X)]
while task:
    d, x, y = hq.heappop(task)
    if d >= v:
        break
    v += d
    ct += 1
    for mx, my in mv:
        nx, ny = x+mx, y+my
        if not (0 <= nx < H and 0 <= ny < W):
            continue
        if seen[nx][ny]:
            continue
        hq.heappush(task, (A[nx][ny], nx, ny))
        seen[nx][ny] = 1

print('Yes' if ct == H*W else 'No')
0