結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー titan23titan23
提出日時 2022-06-25 02:59:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 103,176 KB
最終ジャッジ日時 2024-04-26 08:44:14
合計ジャッジ時間 10,761 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,864 KB
testcase_01 AC 44 ms
53,120 KB
testcase_02 AC 40 ms
52,608 KB
testcase_03 AC 40 ms
53,248 KB
testcase_04 AC 39 ms
52,480 KB
testcase_05 AC 39 ms
52,480 KB
testcase_06 WA -
testcase_07 AC 470 ms
81,748 KB
testcase_08 AC 80 ms
76,552 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 545 ms
81,716 KB
testcase_13 AC 546 ms
82,160 KB
testcase_14 AC 670 ms
101,200 KB
testcase_15 AC 679 ms
101,668 KB
testcase_16 WA -
testcase_17 AC 1,299 ms
102,864 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 41 ms
52,992 KB
testcase_21 AC 41 ms
53,120 KB
testcase_22 AC 696 ms
90,504 KB
testcase_23 RE -
testcase_24 WA -
testcase_25 AC 487 ms
82,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heapify, heappush, heappop
input = lambda: sys.stdin.readline().rstrip()\

dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [1, 0, -1, 1, -1, 1, 0, -1]

#  -----------------------  #

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(len(dx)):
    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