結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー titan23titan23
提出日時 2022-06-25 03:04:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 998 ms / 3,000 ms
コード長 796 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 101,120 KB
最終ジャッジ日時 2024-04-26 08:52:07
合計ジャッジ時間 8,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,992 KB
testcase_01 AC 41 ms
52,736 KB
testcase_02 AC 42 ms
52,608 KB
testcase_03 AC 43 ms
52,992 KB
testcase_04 AC 42 ms
52,864 KB
testcase_05 AC 40 ms
52,608 KB
testcase_06 AC 40 ms
52,864 KB
testcase_07 AC 414 ms
81,152 KB
testcase_08 AC 87 ms
76,800 KB
testcase_09 AC 443 ms
81,408 KB
testcase_10 AC 489 ms
81,624 KB
testcase_11 AC 516 ms
81,680 KB
testcase_12 AC 510 ms
82,304 KB
testcase_13 AC 527 ms
81,464 KB
testcase_14 AC 650 ms
100,992 KB
testcase_15 AC 680 ms
101,120 KB
testcase_16 AC 79 ms
77,056 KB
testcase_17 AC 998 ms
96,756 KB
testcase_18 AC 78 ms
77,312 KB
testcase_19 AC 42 ms
52,992 KB
testcase_20 AC 43 ms
52,864 KB
testcase_21 AC 43 ms
52,736 KB
testcase_22 AC 694 ms
89,868 KB
testcase_23 AC 42 ms
52,992 KB
testcase_24 AC 324 ms
81,324 KB
testcase_25 AC 452 ms
81,408 KB
権限があれば一括ダウンロードができます

ソースコード

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, y, x = 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