結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
|
提出日時 | 2022-10-30 18:13:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,046 ms / 3,000 ms |
コード長 | 935 bytes |
コンパイル時間 | 557 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 99,880 KB |
最終ジャッジ日時 | 2024-07-07 09:59:59 |
合計ジャッジ時間 | 9,895 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#!/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()