結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー titan23titan23
提出日時 2022-06-25 02:53:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 102,016 KB
最終ジャッジ日時 2024-04-26 08:36:45
合計ジャッジ時間 12,392 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 43 ms
52,608 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 525 ms
81,848 KB
testcase_14 WA -
testcase_15 AC 684 ms
101,120 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 42 ms
52,480 KB
testcase_20 WA -
testcase_21 AC 44 ms
53,248 KB
testcase_22 WA -
testcase_23 RE -
testcase_24 AC 331 ms
81,200 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0