結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,564 KB
testcase_01 AC 35 ms
53,564 KB
testcase_02 AC 34 ms
53,564 KB
testcase_03 AC 36 ms
53,564 KB
testcase_04 AC 34 ms
53,564 KB
testcase_05 AC 36 ms
53,564 KB
testcase_06 AC 36 ms
53,564 KB
testcase_07 AC 417 ms
80,904 KB
testcase_08 AC 79 ms
76,292 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 551 ms
81,968 KB
testcase_13 AC 554 ms
81,656 KB
testcase_14 AC 655 ms
99,408 KB
testcase_15 AC 645 ms
99,420 KB
testcase_16 WA -
testcase_17 AC 956 ms
94,980 KB
testcase_18 WA -
testcase_19 AC 33 ms
53,564 KB
testcase_20 AC 34 ms
53,564 KB
testcase_21 AC 35 ms
53,564 KB
testcase_22 AC 770 ms
89,832 KB
testcase_23 RE -
testcase_24 AC 330 ms
80,904 KB
testcase_25 AC 446 ms
81,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

H, W, X, Y = 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 = []
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