結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー AkariAkari
提出日時 2022-05-21 00:15:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,395 ms / 3,000 ms
コード長 827 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 81,668 KB
最終ジャッジ日時 2023-10-20 15:09:57
合計ジャッジ時間 24,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,115 ms
42,660 KB
testcase_01 AC 427 ms
42,752 KB
testcase_02 AC 403 ms
42,752 KB
testcase_03 AC 411 ms
42,752 KB
testcase_04 AC 417 ms
42,752 KB
testcase_05 AC 407 ms
42,752 KB
testcase_06 AC 412 ms
42,752 KB
testcase_07 AC 1,015 ms
43,548 KB
testcase_08 AC 435 ms
48,036 KB
testcase_09 AC 1,066 ms
48,036 KB
testcase_10 AC 1,085 ms
48,036 KB
testcase_11 AC 1,091 ms
48,036 KB
testcase_12 AC 1,073 ms
44,628 KB
testcase_13 AC 1,101 ms
44,736 KB
testcase_14 AC 1,010 ms
60,848 KB
testcase_15 AC 1,009 ms
60,848 KB
testcase_16 AC 413 ms
44,740 KB
testcase_17 AC 1,395 ms
54,016 KB
testcase_18 AC 419 ms
44,740 KB
testcase_19 AC 446 ms
42,752 KB
testcase_20 AC 403 ms
42,752 KB
testcase_21 AC 415 ms
42,752 KB
testcase_22 AC 1,233 ms
48,364 KB
testcase_23 AC 416 ms
42,752 KB
testcase_24 AC 756 ms
44,740 KB
testcase_25 AC 1,014 ms
81,668 KB
権限があれば一括ダウンロードができます

ソースコード

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