結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー Akijin_007Akijin_007
提出日時 2022-05-20 23:46:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,150 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 99,416 KB
最終ジャッジ日時 2023-10-20 14:42:11
合計ジャッジ時間 10,522 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,548 KB
testcase_01 AC 40 ms
53,548 KB
testcase_02 AC 41 ms
53,548 KB
testcase_03 AC 40 ms
53,548 KB
testcase_04 AC 41 ms
53,548 KB
testcase_05 AC 40 ms
53,548 KB
testcase_06 AC 39 ms
53,548 KB
testcase_07 AC 452 ms
80,900 KB
testcase_08 AC 81 ms
76,304 KB
testcase_09 AC 540 ms
81,192 KB
testcase_10 AC 581 ms
81,388 KB
testcase_11 AC 605 ms
81,552 KB
testcase_12 AC 607 ms
81,964 KB
testcase_13 AC 612 ms
81,672 KB
testcase_14 AC 741 ms
99,416 KB
testcase_15 AC 742 ms
99,416 KB
testcase_16 AC 72 ms
76,784 KB
testcase_17 AC 1,097 ms
95,108 KB
testcase_18 AC 71 ms
76,784 KB
testcase_19 AC 40 ms
53,548 KB
testcase_20 AC 40 ms
53,548 KB
testcase_21 AC 40 ms
53,548 KB
testcase_22 AC 837 ms
89,836 KB
testcase_23 WA -
testcase_24 AC 360 ms
80,900 KB
testcase_25 AC 485 ms
81,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

H, W, Y, X = map(int, input().split())
X -= 1
Y -= 1

A = [0] * H
for i in range(H):
    A[i] = list(map(int, input().split()))

import heapq

q = []
# print(A[Y])
s = A[Y][X]

v = [[0] * W for i in range(H)]
v[Y][X] = 1

if X + 1 < W:
    q.append([A[Y][X+1], Y, X+1])
    v[Y][X+1] = 1
if X - 1 > 0:
    q.append([A[Y][X-1], Y, X-1])
    v[Y][X-1] = 1
if Y + 1 < H:
    q.append([A[Y+1][X], Y+1, X])
    v[Y+1][X] = 1
if Y - 1 > 0:
    q.append([A[Y-1][X], Y-1, X])
    v[Y-1][X] = 1

heapq.heapify(q)


dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

f = 1

while len(q) > 0:
    t = heapq.heappop(q)
    a = t[0]
    x = t[1]
    y = t[2]
    if s <= a:
        f = 0
        break
    s += a
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        # print(nx, ny)
        if nx < 0 or nx >= H or ny < 0 or ny >= W:
            continue
        if v[nx][ny] == 1:
            continue
        heapq.heappush(q, [A[nx][ny], nx, ny])
        v[nx][ny] = 1

# for i in range(H):
#     print(v[i])
# print(q)


if f == 0:
    print("No")
else:
    print("Yes")


0