結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2022-04-20 23:52:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,047 ms / 3,000 ms |
| コード長 | 745 bytes |
| コンパイル時間 | 231 ms |
| コンパイル使用メモリ | 82,700 KB |
| 実行使用メモリ | 101,276 KB |
| 最終ジャッジ日時 | 2024-06-26 20:42:25 |
| 合計ジャッジ時間 | 9,354 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import heapq
H,W,Y,X = map(int, input().split())
A = []
for _ in range(H):
A.append(list(map(int, input().split())))
if not(1<=H<=500 and 1<=W<=500 and len(A)==H and 1<=Y<=H and 1<=X<=W):
exit()
for a in A:
if not (len(a)==W and 1<=min(a) and max(a)<=10**9):
exit()
T = [[0]*W for _ in range(H)]
Y,X=Y-1,X-1
heap = []
T[Y][X]=1
V = A[Y][X]
A[Y][X]=0
heapq.heappush(heap,(A[Y][X],Y,X))
HI = [1,0,-1,0]
WI = [0,1,0,-1]
while len(heap):
v,h,w = heapq.heappop(heap)
if V<=v:
print('No')
exit()
V+=v
for i in range(4):
nh=h+HI[i]
nw=w+WI[i]
if 0<=nh<H and 0<=nw<W and T[nh][nw]==0:
T[nh][nw]=1
heapq.heappush(heap,(A[nh][nw],nh,nw))
print('Yes')
H20