結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー tktk_snsntktk_snsn
提出日時 2022-05-20 22:21:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,041 ms / 3,000 ms
コード長 912 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 97,544 KB
最終ジャッジ日時 2023-10-20 13:06:13
合計ジャッジ時間 9,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,436 KB
testcase_01 AC 39 ms
53,436 KB
testcase_02 AC 40 ms
53,436 KB
testcase_03 AC 39 ms
53,436 KB
testcase_04 AC 39 ms
53,436 KB
testcase_05 AC 39 ms
53,436 KB
testcase_06 AC 39 ms
53,436 KB
testcase_07 AC 402 ms
78,596 KB
testcase_08 AC 73 ms
76,468 KB
testcase_09 AC 445 ms
78,520 KB
testcase_10 AC 479 ms
78,804 KB
testcase_11 AC 519 ms
79,640 KB
testcase_12 AC 513 ms
79,064 KB
testcase_13 AC 507 ms
79,232 KB
testcase_14 AC 646 ms
97,544 KB
testcase_15 AC 643 ms
97,544 KB
testcase_16 AC 67 ms
76,824 KB
testcase_17 AC 1,041 ms
93,608 KB
testcase_18 AC 66 ms
76,824 KB
testcase_19 AC 40 ms
53,436 KB
testcase_20 AC 40 ms
53,436 KB
testcase_21 AC 40 ms
53,436 KB
testcase_22 AC 737 ms
87,772 KB
testcase_23 AC 40 ms
53,436 KB
testcase_24 AC 309 ms
79,060 KB
testcase_25 AC 404 ms
78,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 15
dydx4 = ((0, 1), (1, 0), (-1, 0), (0, -1))
dydx8 = ((0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1))


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


def is_inside(x, y):
    return 0 <= x < H and 0 <= y < W


tot = A[X][Y]
A[X][Y] = -1
que = []
for dx, dy in dydx4:
    nx = X + dx
    ny = Y + dy
    if is_inside(nx, ny):
        heapq.heappush(que, (A[nx][ny], nx, ny))
        A[nx][ny] = -1

while que:
    a, xi, yi = heapq.heappop(que)
    if a >= tot:
        print("No")
        exit()
    tot += a
    for dx, dy in dydx4:
        nx = xi + dx
        ny = yi + dy
        if is_inside(nx, ny) and A[nx][ny] != -1:
            heapq.heappush(que, (A[nx][ny], nx, ny))
            A[nx][ny] = -1

print("Yes")
0