結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー first_vilfirst_vil
提出日時 2022-05-20 22:20:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 405 ms / 3,000 ms
コード長 1,110 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 87,736 KB
最終ジャッジ日時 2023-10-20 13:04:03
合計ジャッジ時間 5,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,424 KB
testcase_01 AC 42 ms
53,424 KB
testcase_02 AC 42 ms
53,424 KB
testcase_03 AC 41 ms
53,424 KB
testcase_04 AC 43 ms
53,424 KB
testcase_05 AC 39 ms
53,424 KB
testcase_06 AC 39 ms
53,424 KB
testcase_07 AC 207 ms
78,256 KB
testcase_08 AC 75 ms
76,140 KB
testcase_09 AC 195 ms
78,564 KB
testcase_10 AC 226 ms
78,728 KB
testcase_11 AC 236 ms
78,728 KB
testcase_12 AC 231 ms
78,788 KB
testcase_13 AC 238 ms
78,860 KB
testcase_14 AC 257 ms
87,736 KB
testcase_15 AC 252 ms
87,736 KB
testcase_16 AC 69 ms
76,636 KB
testcase_17 AC 405 ms
86,148 KB
testcase_18 AC 66 ms
76,636 KB
testcase_19 AC 38 ms
53,424 KB
testcase_20 AC 41 ms
53,424 KB
testcase_21 AC 39 ms
53,424 KB
testcase_22 AC 327 ms
83,580 KB
testcase_23 AC 41 ms
53,424 KB
testcase_24 AC 177 ms
78,464 KB
testcase_25 AC 209 ms
78,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
mod = int(1e9 + 7)
# mod = 998244353

from heapq import heapify, heappop, heappush

h, w, y, x = mi()
y, x = y - 1, x - 1
a = [li() for _ in range(h)]
cur = a[y][x]
a[y][x] = 0
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
que = []
heapify(que)
for i in range(4):
    ny, nx = y + dy[i], x + dx[i]
    if 0 <= ny < h and 0 <= nx < w:
        heappush(que, (a[ny][nx], ny * w + nx))
        a[ny][nx] = 0
while que:
    v, tmp = heappop(que)
    y, x = tmp // w, tmp % w
    if cur <= v:
        print("No")
        exit(0)
    cur += v
    for i in range(4):
        ny, nx = y + dy[i], x + dx[i]
        if 0 <= ny < h and 0 <= nx < w and a[ny][nx]:
            heappush(que, (a[ny][nx], ny * w + nx))
            a[ny][nx] = 0
print("Yes")
0