結果
| 問題 | No.1949 足し算するだけのパズルゲーム(2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-30 18:13:56 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 654 ms / 3,000 ms |
| コード長 | 935 bytes |
| 記録 | |
| コンパイル時間 | 280 ms |
| コンパイル使用メモリ | 85,740 KB |
| 実行使用メモリ | 104,912 KB |
| 最終ジャッジ日時 | 2026-03-29 00:10:42 |
| 合計ジャッジ時間 | 6,915 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()