結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ntudantuda
提出日時 2022-10-24 20:23:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,102 ms / 3,000 ms
コード長 877 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 101,976 KB
最終ジャッジ日時 2023-09-15 21:56:07
合計ジャッジ時間 11,573 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,632 KB
testcase_01 AC 93 ms
71,624 KB
testcase_02 AC 92 ms
71,580 KB
testcase_03 AC 94 ms
71,676 KB
testcase_04 AC 95 ms
71,796 KB
testcase_05 AC 95 ms
71,724 KB
testcase_06 AC 92 ms
71,436 KB
testcase_07 AC 611 ms
81,792 KB
testcase_08 AC 135 ms
78,748 KB
testcase_09 AC 627 ms
81,664 KB
testcase_10 AC 610 ms
81,328 KB
testcase_11 AC 704 ms
82,780 KB
testcase_12 AC 685 ms
82,544 KB
testcase_13 AC 707 ms
81,704 KB
testcase_14 AC 1,102 ms
101,888 KB
testcase_15 AC 1,099 ms
101,976 KB
testcase_16 AC 123 ms
78,280 KB
testcase_17 AC 504 ms
81,628 KB
testcase_18 AC 123 ms
77,908 KB
testcase_19 AC 95 ms
71,768 KB
testcase_20 AC 94 ms
71,432 KB
testcase_21 AC 95 ms
71,772 KB
testcase_22 AC 560 ms
81,748 KB
testcase_23 AC 95 ms
71,712 KB
testcase_24 AC 427 ms
82,004 KB
testcase_25 AC 614 ms
81,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
from collections import deque

H, W, Y, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

now = A[Y - 1][X - 1]
A[Y - 1][X - 1] = 0
dir = [[0, 1], [1, 0], [0, -1], [-1, 0]]
cnt = 1
Q = deque([(Y - 1, X - 1)])
Q2 = []
flag = 1
while flag:
    flag = 0
    while Q:
        i, j = Q.pop()
        for di, dj in dir:
            i2 = i + di
            j2 = j + dj
            if 0 <= i2 < H and 0 <= j2 < W:
                if A[i2][j2] > 0:
                    heapq.heappush(Q2, (A[i2][j2], i2, j2))
                    A[i2][j2] = 0
    while Q2:
        a, i, j = heapq.heappop(Q2)
        if a < now:
            flag = 1
            now += a
            Q.append((i, j))
            cnt += 1
        else:
            heapq.heappush(Q2, (a, i, j))
            break

if cnt == H * W:
    print("Yes")
else:
    print("No")
0