結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー chineristACchineristAC
提出日時 2022-05-20 22:12:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,060 ms / 3,000 ms
コード長 952 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 100,800 KB
最終ジャッジ日時 2023-10-20 12:55:30
合計ジャッジ時間 9,646 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
56,072 KB
testcase_01 AC 46 ms
56,072 KB
testcase_02 AC 46 ms
56,072 KB
testcase_03 AC 48 ms
56,072 KB
testcase_04 AC 47 ms
56,072 KB
testcase_05 AC 47 ms
56,072 KB
testcase_06 AC 46 ms
56,072 KB
testcase_07 AC 425 ms
81,660 KB
testcase_08 AC 88 ms
78,756 KB
testcase_09 AC 457 ms
81,576 KB
testcase_10 AC 500 ms
81,876 KB
testcase_11 AC 520 ms
82,240 KB
testcase_12 AC 511 ms
82,524 KB
testcase_13 AC 512 ms
82,176 KB
testcase_14 AC 663 ms
100,800 KB
testcase_15 AC 674 ms
100,800 KB
testcase_16 AC 77 ms
77,660 KB
testcase_17 AC 1,060 ms
96,948 KB
testcase_18 AC 78 ms
77,664 KB
testcase_19 AC 48 ms
56,076 KB
testcase_20 AC 47 ms
56,076 KB
testcase_21 AC 46 ms
56,076 KB
testcase_22 AC 724 ms
90,832 KB
testcase_23 AC 46 ms
56,076 KB
testcase_24 AC 323 ms
81,544 KB
testcase_25 AC 461 ms
82,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
import heapq
from itertools import permutations
from math import gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

INF = 10**17

H,W,s,t = mi()
A = [li() for i in range(H)]
s,t = s-1,t-1

move = [(-1,0),(1,0),(0,1),(0,-1)]

tmp = A[s][t]
pq = []
insert = [[False]*W for i in range(H)]
insert[s][t] = True
for x,y in move:
    nx,ny = x+s,y+t
    if 0 <= nx < H and 0 <= ny < W:
        heapq.heappush(pq,(A[nx][ny],nx,ny))
        insert[nx][ny] = True

while pq:
    val,x,y = heapq.heappop(pq)
    if val < tmp:
        tmp += val
        for dx,dy in move:
            nx,ny = x+dx,y+dy
            if 0 <= nx < H and 0 <= ny < W and not insert[nx][ny]:
                heapq.heappush(pq,(A[nx][ny],nx,ny))
                insert[nx][ny] = True
    else:
        print("No")
        break
else:
    print("Yes")

    
0