結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー pitPpitP
提出日時 2022-05-21 13:30:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,069 ms / 3,000 ms
コード長 787 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 100,800 KB
最終ジャッジ日時 2023-10-20 16:08:40
合計ジャッジ時間 9,195 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,580 KB
testcase_01 AC 38 ms
53,580 KB
testcase_02 AC 39 ms
53,580 KB
testcase_03 AC 38 ms
53,580 KB
testcase_04 AC 39 ms
53,580 KB
testcase_05 AC 40 ms
53,580 KB
testcase_06 AC 38 ms
53,580 KB
testcase_07 AC 418 ms
80,772 KB
testcase_08 AC 75 ms
76,460 KB
testcase_09 AC 457 ms
81,008 KB
testcase_10 AC 491 ms
81,608 KB
testcase_11 AC 522 ms
81,424 KB
testcase_12 AC 507 ms
81,392 KB
testcase_13 AC 523 ms
81,388 KB
testcase_14 AC 674 ms
100,800 KB
testcase_15 AC 678 ms
100,792 KB
testcase_16 AC 66 ms
76,932 KB
testcase_17 AC 1,069 ms
96,036 KB
testcase_18 AC 66 ms
76,928 KB
testcase_19 AC 37 ms
53,580 KB
testcase_20 AC 38 ms
53,580 KB
testcase_21 AC 39 ms
53,580 KB
testcase_22 AC 727 ms
89,936 KB
testcase_23 AC 39 ms
53,580 KB
testcase_24 AC 313 ms
80,780 KB
testcase_25 AC 454 ms
81,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.readline


h,w,y,x = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
y -= 1
x -= 1

visited = [[False]*w for _ in range(h)]

hq = []
now = a[y][x]
visited[y][x] = True

didj = [(1,0),(0,1),(0,-1),(-1,0)]
for di,dj in didj:
    ni = y + di
    nj = x + dj
    if 0 <= ni < h and 0 <= nj < w:
        heapq.heappush(hq,(a[ni][nj] , ni,nj))
        visited[ni][nj] = True

while hq:
    a_nxt,i,j = heapq.heappop(hq)
    if now <= a_nxt:
        print("No")
        exit()
    now += a_nxt
    for di , dj in didj:
        ni = i + di
        nj = j + dj
        if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
            heapq.heappush(hq,(a[ni][nj],ni,nj))
            visited[ni][nj] = True

print("Yes")
0