結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
![]() |
提出日時 | 2022-05-20 22:21:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 891 ms / 3,000 ms |
コード長 | 912 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 99,052 KB |
最終ジャッジ日時 | 2024-09-20 08:35:06 |
合計ジャッジ時間 | 7,965 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10 ** 15 dydx4 = ((0, 1), (1, 0), (-1, 0), (0, -1)) dydx8 = ((0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1)) H, W, X, Y = map(int, input().split()) X -= 1 Y -= 1 A = list(list(map(int, input().split())) for _ in range(H)) def is_inside(x, y): return 0 <= x < H and 0 <= y < W tot = A[X][Y] A[X][Y] = -1 que = [] for dx, dy in dydx4: nx = X + dx ny = Y + dy if is_inside(nx, ny): heapq.heappush(que, (A[nx][ny], nx, ny)) A[nx][ny] = -1 while que: a, xi, yi = heapq.heappop(que) if a >= tot: print("No") exit() tot += a for dx, dy in dydx4: nx = xi + dx ny = yi + dy if is_inside(nx, ny) and A[nx][ny] != -1: heapq.heappush(que, (A[nx][ny], nx, ny)) A[nx][ny] = -1 print("Yes")