結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー hiragnhiragn
提出日時 2022-12-14 19:48:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,140 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2024-04-25 23:14:02
合計ジャッジ時間 9,700 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 28 ms
11,008 KB
testcase_03 AC 28 ms
10,880 KB
testcase_04 AC 26 ms
10,880 KB
testcase_05 AC 27 ms
10,880 KB
testcase_06 AC 26 ms
11,008 KB
testcase_07 AC 506 ms
21,888 KB
testcase_08 AC 97 ms
23,040 KB
testcase_09 AC 531 ms
23,040 KB
testcase_10 AC 576 ms
23,040 KB
testcase_11 AC 587 ms
23,168 KB
testcase_12 AC 588 ms
23,040 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 87 ms
14,976 KB
testcase_17 AC 753 ms
23,680 KB
testcase_18 AC 85 ms
14,976 KB
testcase_19 WA -
testcase_20 AC 28 ms
11,008 KB
testcase_21 WA -
testcase_22 AC 630 ms
22,016 KB
testcase_23 AC 28 ms
11,008 KB
testcase_24 AC 306 ms
15,104 KB
testcase_25 AC 519 ms
22,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush


def main():
    h, w, sy, sx = map(int, input().split())
    sy -= 1
    sx -= 1
    a = [list(map(int, input().split())) for _ in range(h)]

    used = [[False] * w for _ in range(h)]
    used[sy][sx] = True
    hq = [(a[sy][sx], sy, sx)]
    heapify(hq)
    cnt = 1
    cur_atk = a[sy][sx]
    a[sy][sx] = 0
    dx = [1, 0, -1, 0, 1, -1, -1, 1]
    dy = [0, 1, 0, -1, 1, 1, -1, -1]
    for i in range(4):
        ny = sy + dy[i]
        nx = sx + dx[i]
        if 0 <= ny < h and 0 <= nx < w:
            used[ny][nx] = True
            heappush(hq, (a[ny][nx], ny, nx))
            cnt += 1

    while hq:
        atk, y, x = heappop(hq)
        if cur_atk <= atk:
            break

        cur_atk += atk
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < h and 0 <= nx < w and not used[ny][nx]:
                used[ny][nx] = True
                heappush(hq, (a[ny][nx], ny, nx))
                cnt += 1

    if cnt == h * w:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

"""
WIP
"""
0