結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー roarisroaris
提出日時 2022-05-20 23:20:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 419 ms / 3,000 ms
コード長 798 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 91,176 KB
最終ジャッジ日時 2023-10-20 14:12:28
合計ジャッジ時間 5,250 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,552 KB
testcase_01 AC 43 ms
55,552 KB
testcase_02 AC 42 ms
55,552 KB
testcase_03 AC 43 ms
55,552 KB
testcase_04 AC 42 ms
55,552 KB
testcase_05 AC 41 ms
55,552 KB
testcase_06 AC 43 ms
55,552 KB
testcase_07 AC 232 ms
80,768 KB
testcase_08 AC 81 ms
76,612 KB
testcase_09 AC 217 ms
80,876 KB
testcase_10 AC 235 ms
80,872 KB
testcase_11 AC 256 ms
80,872 KB
testcase_12 AC 236 ms
81,132 KB
testcase_13 AC 260 ms
81,676 KB
testcase_14 AC 290 ms
91,176 KB
testcase_15 AC 286 ms
91,176 KB
testcase_16 AC 68 ms
77,064 KB
testcase_17 AC 419 ms
89,012 KB
testcase_18 AC 69 ms
77,060 KB
testcase_19 AC 41 ms
55,552 KB
testcase_20 AC 42 ms
55,552 KB
testcase_21 AC 43 ms
55,552 KB
testcase_22 AC 330 ms
85,944 KB
testcase_23 AC 40 ms
55,552 KB
testcase_24 AC 187 ms
80,976 KB
testcase_25 AC 234 ms
81,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *
from heapq import *

H, W, X, Y = map(int, input().split())
X -= 1
Y -= 1
A = [list(map(int, input().split())) for _ in range(H)]
f = [[False]*W for _ in range(H)]
f[X][Y] = True
pq = []

for nx, ny in [(X-1, Y), (X+1, Y), (X, Y-1), (X, Y+1)]:
    if 0<=nx<H and 0<=ny<W:
        heappush(pq, (A[nx][ny], nx*1000+ny))
        f[nx][ny] = True

now = A[X][Y]

while pq:
    if pq[0][0]<now:
        a, xy = heappop(pq)
        x, y = divmod(xy, 1000)
        now += a
        
        for nx, ny in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]:
            if 0<=nx<H and 0<=ny<W and not f[nx][ny]:
                heappush(pq, (A[nx][ny], nx*1000+ny))
                f[nx][ny] = True
    else:
        exit(print('No'))
    
print('Yes')
0