結果
| 問題 | 
                            No.1949 足し算するだけのパズルゲーム(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-06-25 02:54:10 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 795 bytes | 
| コンパイル時間 | 545 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 102,016 KB | 
| 最終ジャッジ日時 | 2024-11-08 22:16:16 | 
| 合計ジャッジ時間 | 10,647 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 WA * 6 RE * 1 | 
ソースコード
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, x, y = 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')