結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー Akijin_007Akijin_007
提出日時 2022-05-20 23:48:33
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 955 ms / 3,000 ms
コード長 1,152 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 99,204 KB
最終ジャッジ日時 2023-10-20 14:43:59
合計ジャッジ時間 9,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,496 KB
testcase_01 AC 33 ms
53,496 KB
testcase_02 AC 34 ms
53,496 KB
testcase_03 AC 31 ms
53,496 KB
testcase_04 AC 32 ms
53,496 KB
testcase_05 AC 32 ms
53,496 KB
testcase_06 AC 36 ms
53,496 KB
testcase_07 AC 417 ms
80,876 KB
testcase_08 AC 79 ms
76,296 KB
testcase_09 AC 512 ms
81,188 KB
testcase_10 AC 547 ms
81,396 KB
testcase_11 AC 579 ms
81,544 KB
testcase_12 AC 568 ms
81,960 KB
testcase_13 AC 576 ms
81,656 KB
testcase_14 AC 682 ms
99,196 KB
testcase_15 AC 685 ms
99,204 KB
testcase_16 AC 65 ms
76,776 KB
testcase_17 AC 955 ms
95,108 KB
testcase_18 AC 65 ms
76,776 KB
testcase_19 AC 34 ms
53,544 KB
testcase_20 AC 32 ms
53,544 KB
testcase_21 AC 34 ms
53,544 KB
testcase_22 AC 770 ms
89,816 KB
testcase_23 AC 36 ms
53,544 KB
testcase_24 AC 329 ms
80,892 KB
testcase_25 AC 444 ms
81,312 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