結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー tassei903tassei903
提出日時 2022-05-21 09:52:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 947 ms / 3,000 ms
コード長 1,111 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 99,456 KB
最終ジャッジ日時 2023-10-20 15:47:07
合計ジャッジ時間 8,995 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,532 KB
testcase_01 AC 35 ms
53,532 KB
testcase_02 AC 35 ms
53,532 KB
testcase_03 AC 36 ms
53,532 KB
testcase_04 AC 34 ms
53,532 KB
testcase_05 AC 35 ms
53,532 KB
testcase_06 AC 35 ms
53,532 KB
testcase_07 AC 394 ms
80,928 KB
testcase_08 AC 71 ms
76,404 KB
testcase_09 AC 419 ms
80,976 KB
testcase_10 AC 467 ms
81,172 KB
testcase_11 AC 489 ms
81,468 KB
testcase_12 AC 483 ms
81,924 KB
testcase_13 AC 481 ms
81,584 KB
testcase_14 AC 602 ms
99,456 KB
testcase_15 AC 586 ms
99,456 KB
testcase_16 AC 63 ms
76,908 KB
testcase_17 AC 947 ms
96,528 KB
testcase_18 AC 63 ms
76,904 KB
testcase_19 AC 34 ms
53,532 KB
testcase_20 AC 36 ms
53,532 KB
testcase_21 AC 37 ms
53,532 KB
testcase_22 AC 678 ms
90,208 KB
testcase_23 AC 35 ms
53,532 KB
testcase_24 AC 285 ms
80,676 KB
testcase_25 AC 435 ms
81,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

h,w,y,x = na()
y-=1
x-=1
a = [na() for i in range(h)]

from heapq import *
hq = [(a[y][x], y, x)]
z = a[y][x]
hq = []
visited = [[0 for j in range(w)]for i in range(h)]
visited[y][x] = 1
for dy, dx in [[1,0],[-1,0],[0,1],[0,-1]]:
    nx = x + dx
    ny = y + dy
    if 0 <= ny < h and 0 <= nx < w and visited[ny][nx]^1:
        heappush(hq, (a[ny][nx],ny,nx))
        visited[ny][nx] = 1
ans = 1
while hq:
    v,y,x = heappop(hq)#print(v,y,x)
    if z <= v:
        ans = 0
        break
    z += v
    for dy, dx in [[1,0],[-1,0],[0,1],[0,-1]]:
        nx = x + dx
        ny = y + dy
        if 0 <= ny < h and 0 <= nx < w and visited[ny][nx]^1:
            heappush(hq, (a[ny][nx],ny,nx))
            visited[ny][nx] = 1
if ans:
    Yes()
else:
    No()
0