結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー roarisroaris
提出日時 2022-05-20 23:16:22
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 775 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 81,752 KB
実行使用メモリ 303,908 KB
最終ジャッジ日時 2023-10-20 14:09:37
合計ジャッジ時間 5,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,552 KB
testcase_01 AC 42 ms
55,552 KB
testcase_02 AC 43 ms
55,552 KB
testcase_03 AC 43 ms
55,552 KB
testcase_04 AC 43 ms
55,552 KB
testcase_05 AC 43 ms
55,552 KB
testcase_06 AC 42 ms
55,552 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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)]
beat = [[False]*W for _ in range(H)]
beat[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))

now = A[X][Y]

while pq:
    if pq[0][0]<now:
        a, xy = heappop(pq)
        x, y = divmod(xy, 1000)
        now += a
        beat[x][y] = True
        
        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 beat[nx][ny]:
                heappush(pq, (A[nx][ny], nx*1000+ny))
    else:
        exit(print('No'))
    
print('Yes')
0