結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-20 22:12:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 913 ms / 3,000 ms |
| コード長 | 952 bytes |
| コンパイル時間 | 138 ms |
| コンパイル使用メモリ | 82,024 KB |
| 実行使用メモリ | 101,128 KB |
| 最終ジャッジ日時 | 2024-09-20 08:24:08 |
| 合計ジャッジ時間 | 8,329 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import sys,random,bisect
from collections import deque,defaultdict
import heapq
from itertools import permutations
from math import gcd
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
INF = 10**17
H,W,s,t = mi()
A = [li() for i in range(H)]
s,t = s-1,t-1
move = [(-1,0),(1,0),(0,1),(0,-1)]
tmp = A[s][t]
pq = []
insert = [[False]*W for i in range(H)]
insert[s][t] = True
for x,y in move:
nx,ny = x+s,y+t
if 0 <= nx < H and 0 <= ny < W:
heapq.heappush(pq,(A[nx][ny],nx,ny))
insert[nx][ny] = True
while pq:
val,x,y = heapq.heappop(pq)
if val < tmp:
tmp += val
for dx,dy in move:
nx,ny = x+dx,y+dy
if 0 <= nx < H and 0 <= ny < W and not insert[nx][ny]:
heapq.heappush(pq,(A[nx][ny],nx,ny))
insert[nx][ny] = True
else:
print("No")
break
else:
print("Yes")