結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー とりゐとりゐ
提出日時 2022-05-20 22:13:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,163 ms / 3,000 ms
コード長 1,008 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 102,764 KB
最終ジャッジ日時 2023-10-20 12:56:17
合計ジャッジ時間 9,470 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,400 KB
testcase_01 AC 41 ms
53,400 KB
testcase_02 AC 41 ms
53,400 KB
testcase_03 AC 40 ms
53,400 KB
testcase_04 AC 41 ms
53,400 KB
testcase_05 AC 40 ms
53,400 KB
testcase_06 AC 39 ms
53,400 KB
testcase_07 AC 468 ms
82,500 KB
testcase_08 AC 86 ms
78,924 KB
testcase_09 AC 473 ms
82,484 KB
testcase_10 AC 511 ms
82,712 KB
testcase_11 AC 549 ms
82,900 KB
testcase_12 AC 530 ms
83,540 KB
testcase_13 AC 548 ms
83,104 KB
testcase_14 AC 722 ms
102,760 KB
testcase_15 AC 723 ms
102,764 KB
testcase_16 AC 78 ms
76,528 KB
testcase_17 AC 1,163 ms
98,076 KB
testcase_18 AC 76 ms
76,520 KB
testcase_19 AC 41 ms
53,400 KB
testcase_20 AC 41 ms
53,400 KB
testcase_21 AC 40 ms
53,400 KB
testcase_22 AC 770 ms
92,096 KB
testcase_23 AC 40 ms
53,400 KB
testcase_24 AC 341 ms
82,944 KB
testcase_25 AC 527 ms
83,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w,sy,sx=map(int,input().split())
a=[]
for _ in range(h):
  a.append(list(map(int,input().split())))

import heapq
class HQ:
  def __init__(self,a):
    self.hq=a.copy()
    heapq.heapify(self.hq)
  
  def get(self):
    if self.hq:
      return self.hq[0]
    else:
      return False
  
  def len(self):
    return len(self.hq)

  def pop(self):
    if self.hq:
      return heapq.heappop(self.hq)
    else:
      return False
  
  def append(self,i):
    heapq.heappush(self.hq,i)

dxdy=[(0,1),(1,0),(0,-1),(-1,0)]
seen=[[False]*w for i in range(h)]

now=0
hq=HQ([(a[sy-1][sx-1],sy-1,sx-1)])
added=[[False]*w for i in range(h)]

while hq.len()>0:
  c,x,y=hq.pop()
  #print(c,x,y,now)
  if seen[x][y]:continue
  seen[x][y]=True
  if x==sy-1 and y==sx-1:
    now+=c
  else:
    if now>c:
      now+=c
    else:
      print('No')
      exit()
  for dx,dy in dxdy:
    nx,ny=x+dx,y+dy
    if 0<=nx<h and 0<=ny<w and not added[nx][ny]:
      hq.append((a[nx][ny],nx,ny))
      added[nx][ny]=True

print('Yes')
0