結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-06-25 03:04:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,056 ms / 3,000 ms |
| コード長 | 796 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 100,992 KB |
| 最終ジャッジ日時 | 2024-11-08 22:49:24 |
| 合計ジャッジ時間 | 9,254 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import sys
from heapq import heapify, heappush, heappop
input = lambda: sys.stdin.readline().rstrip()\
dx = [-1, 0, 0, 1]
dy = [0, -1, 1, 0]
# ----------------------- #
h, w, y, x = map(int, input().split())
x -= 1
y -= 1
A = [list(map(int, input().split())) for _ in range(h)]
hq = [(0, y, x)]
now = A[y][x]
seen = [[False]*w for _ in range(h)]
seen[y][x] = True
def is_infield(y, x):
return 0 <= y < h and 0 <= x < w
killed = 0
while hq:
a, vy, vx = heappop(hq)
if now <= a:
print('No')
exit()
killed += 1
now += a
for i in range(4):
ny, nx = vy+dy[i], vx+dx[i]
if not is_infield(ny, nx):
continue
if seen[ny][nx]:
continue
seen[ny][nx] = True
heappush(hq, (A[ny][nx], ny, nx))
if killed == h*w:
print('Yes')
else:
print('No')