結果
| 問題 | No.1949 足し算するだけのパズルゲーム(2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-20 22:02:03 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 656 ms / 3,000 ms |
| コード長 | 825 bytes |
| 記録 | |
| コンパイル時間 | 208 ms |
| コンパイル使用メモリ | 85,068 KB |
| 実行使用メモリ | 103,916 KB |
| 最終ジャッジ日時 | 2026-04-08 19:50:35 |
| 合計ジャッジ時間 | 6,313 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
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)]
hq = []
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
tot = A[x][y]
used = [[False] * w for _ in range(h)]
used[x][y] = True
for dx, dy in directions:
nx = x + dx
ny = y + dy
if nx == -1 or nx == h or ny == -1 or ny == w:
continue
heappush(hq, (A[nx][ny], nx, ny))
used[nx][ny] = True
while hq:
a, x, y = heappop(hq)
if a >= tot:
print("No")
exit()
tot += a
for dx, dy in directions:
nx = x + dx
ny = y + dy
if nx == -1 or nx == h or ny == -1 or ny == w:
continue
if used[nx][ny]:
continue
heappush(hq, (A[nx][ny], nx, ny))
used[nx][ny] = True
print("Yes")