結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー rin204rin204
提出日時 2022-05-20 21:59:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 81,480 KB
実行使用メモリ 99,084 KB
最終ジャッジ日時 2023-10-20 12:36:37
合計ジャッジ時間 11,658 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,340 KB
testcase_01 AC 40 ms
53,340 KB
testcase_02 AC 41 ms
53,340 KB
testcase_03 AC 41 ms
53,340 KB
testcase_04 AC 40 ms
53,340 KB
testcase_05 AC 42 ms
53,340 KB
testcase_06 AC 41 ms
53,340 KB
testcase_07 AC 439 ms
80,428 KB
testcase_08 AC 88 ms
76,092 KB
testcase_09 AC 461 ms
80,556 KB
testcase_10 AC 497 ms
80,852 KB
testcase_11 AC 534 ms
80,892 KB
testcase_12 AC 522 ms
81,356 KB
testcase_13 WA -
testcase_14 AC 687 ms
99,084 KB
testcase_15 AC 686 ms
99,084 KB
testcase_16 AC 76 ms
76,572 KB
testcase_17 AC 1,141 ms
95,780 KB
testcase_18 AC 76 ms
76,568 KB
testcase_19 AC 43 ms
53,340 KB
testcase_20 AC 43 ms
53,340 KB
testcase_21 AC 43 ms
53,340 KB
testcase_22 AC 762 ms
89,656 KB
testcase_23 AC 42 ms
53,340 KB
testcase_24 WA -
testcase_25 AC 478 ms
80,924 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:
        break
    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

if tot > A[-1][-1] and used[-1][-1]:
    print("Yes")
else:
    print("No")
0