結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 👑 rin204rin204
提出日時 2022-05-20 22:02:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,054 ms / 3,000 ms
コード長 825 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 81,576 KB
実行使用メモリ 99,088 KB
最終ジャッジ日時 2023-10-20 12:41:18
合計ジャッジ時間 9,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,376 KB
testcase_01 AC 40 ms
53,376 KB
testcase_02 AC 41 ms
53,376 KB
testcase_03 AC 43 ms
53,376 KB
testcase_04 AC 39 ms
53,376 KB
testcase_05 AC 39 ms
53,376 KB
testcase_06 AC 39 ms
53,376 KB
testcase_07 AC 420 ms
80,420 KB
testcase_08 AC 85 ms
76,124 KB
testcase_09 AC 461 ms
80,552 KB
testcase_10 AC 487 ms
80,856 KB
testcase_11 AC 532 ms
80,864 KB
testcase_12 AC 520 ms
81,364 KB
testcase_13 AC 507 ms
81,056 KB
testcase_14 AC 670 ms
99,084 KB
testcase_15 AC 658 ms
99,088 KB
testcase_16 AC 73 ms
76,604 KB
testcase_17 AC 1,054 ms
95,784 KB
testcase_18 AC 72 ms
76,608 KB
testcase_19 AC 38 ms
53,380 KB
testcase_20 AC 39 ms
53,380 KB
testcase_21 AC 40 ms
53,380 KB
testcase_22 AC 740 ms
89,644 KB
testcase_23 AC 41 ms
53,380 KB
testcase_24 AC 316 ms
80,372 KB
testcase_25 AC 460 ms
80,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

h, w, x, y = map(int, input().split())
x -= 1
y -= 1
A = [list(map(int, input().split())) for _ in range(h)]
hq = []
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
tot = A[x][y]
used = [[False] * w for _ in range(h)]
used[x][y] = True

for dx, dy in directions:
    nx = x + dx
    ny = y + dy
    if nx == -1 or nx == h or ny == -1 or ny == w:
        continue
    heappush(hq, (A[nx][ny], nx, ny))
    used[nx][ny] = True

while hq:
    a, x, y = heappop(hq)
    if a >= tot:
        print("No")
        exit()
    tot += a
    for dx, dy in directions:
        nx = x + dx
        ny = y + dy
        if nx == -1 or nx == h or ny == -1 or ny == w:
            continue
        if used[nx][ny]:
            continue
        heappush(hq, (A[nx][ny], nx, ny))
        used[nx][ny] = True


print("Yes")
0