結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー kept1994kept1994
提出日時 2022-10-30 18:13:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 970 ms / 3,000 ms
コード長 935 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 102,220 KB
最終ジャッジ日時 2023-09-21 16:14:13
合計ジャッジ時間 11,396 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,548 KB
testcase_01 AC 75 ms
71,252 KB
testcase_02 AC 75 ms
71,284 KB
testcase_03 AC 74 ms
71,184 KB
testcase_04 AC 74 ms
71,340 KB
testcase_05 AC 75 ms
71,356 KB
testcase_06 AC 74 ms
71,392 KB
testcase_07 AC 423 ms
82,692 KB
testcase_08 AC 111 ms
78,340 KB
testcase_09 AC 476 ms
82,628 KB
testcase_10 AC 511 ms
83,120 KB
testcase_11 AC 548 ms
83,608 KB
testcase_12 AC 529 ms
83,340 KB
testcase_13 AC 535 ms
82,836 KB
testcase_14 AC 655 ms
101,928 KB
testcase_15 AC 650 ms
102,220 KB
testcase_16 AC 106 ms
77,944 KB
testcase_17 AC 970 ms
98,140 KB
testcase_18 AC 103 ms
78,020 KB
testcase_19 AC 76 ms
71,432 KB
testcase_20 AC 76 ms
71,352 KB
testcase_21 AC 75 ms
71,460 KB
testcase_22 AC 711 ms
92,244 KB
testcase_23 AC 74 ms
71,372 KB
testcase_24 AC 332 ms
82,484 KB
testcase_25 AC 461 ms
82,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
import heapq
INF = 10 ** 16

def main():
    H, W, Y, X = map(int, input().split())
    G = []
    for _ in range(H):
        G.append(list(map(int, input().split())))
    hq = [(0, Y - 1, X - 1)]
    heapq.heapify(hq)
    seen = [[0] * W for _ in range(H)]
    seen[Y - 1][X - 1] = 1
    now = G[Y - 1][X - 1]
    G[Y - 1][X - 1] = 0
    while hq:
        cost, nowy, nowx = heapq.heappop(hq)
        if cost >= now:
            print("No")
            return
        now += cost
        for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
            nexty = nowy + dy
            nextx = nowx + dx
            if nexty < 0 or nextx < 0 or nexty >= H or nextx >= W or seen[nexty][nextx]:
                continue
            
            heapq.heappush(hq, (G[nexty][nextx], nexty, nextx))
            seen[nexty][nextx] = 1
        
    print("Yes")
    return


if __name__ == '__main__':
    main()
0