結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー Akari
提出日時 2022-05-21 00:15:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,547 ms / 3,000 ms
コード長 827 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 60,016 KB
最終ジャッジ日時 2024-09-20 10:39:57
合計ジャッジ時間 24,919 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np
from heapq import heappush, heappop


def main():
    h, w, sy, sx = map(int, input().split())
    A = np.fromstring(sys.stdin.read(), np.int64, sep=' ').reshape(-1, w)
    sy -= 1
    sx -= 1
    b = A[sy, sx]
    A[sy, sx] = 0
    q = [(0, sy, sx)]
    cnt = 0
    dyx = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    B = np.zeros_like(A, np.bool_)
    B[sy, sx] = True
    while q:
        a, y, x = heappop(q)
        if b <= a: break
        cnt += 1
        b += a
        for i in range(4):
            dy, dx = dyx[i]
            Y, X = y + dy, x + dx
            if Y < 0 or Y >= h or X < 0 or X >= w: continue
            if B[Y, X]: continue
            heappush(q, (A[Y, X], Y, X))
            B[Y, X] = True
    print('Yes' if cnt == h * w else 'No')




if __name__ == '__main__':
    main()
0