結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2022-05-20 22:33:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 689 ms / 3,000 ms |
| コード長 | 691 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 97,916 KB |
| 最終ジャッジ日時 | 2024-09-20 08:49:27 |
| 合計ジャッジ時間 | 7,412 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
from heapq import heappop, heappush
h, w, x, y = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
x -= 1
y -= 1
dis = [1, 0, -1, 0]
djs = [0, 1, 0, -1]
added = [[False] * w for _ in range(h)]
added[x][y] = True
q = []
def add_neighbor(i, j):
for di, dj in zip(dis, djs):
ni = i + di
nj = j + dj
if 0 <= ni < h and 0 <= nj < w and not added[ni][nj]:
added[ni][nj] = True
heappush(q, (a[ni][nj], (ni, nj)))
now = a[x][y]
added[x][y] = True
add_neighbor(x, y)
while q:
v, (i, j) = heappop(q)
if v >= now:
print('No')
break
now += v
add_neighbor(i, j)
else:
print('Yes')
Kude