結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー lilictaka
提出日時 2022-05-20 23:37:27
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 849 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,576 KB
実行使用メモリ 144,504 KB
最終ジャッジ日時 2024-09-20 10:03:44
合計ジャッジ時間 9,004 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 2 RE * 8 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,Y,X = map(int,input().split())

seen = [[False] * W for _ in range(H)]
INF = float('inf')
memo = [[-INF] * W for _ in range(H)]
A = []
for _ in range(H):
    tmp = list(map(int,input().split()))
    A.append(tmp)
def check(h,w):
    if 0 <= h < H and 0 <= w < W:
        return True
    else:
        return False
ans = False
def dfs(h,w,a):
    global ans
    if h == H -1 and w == W-1:
        ans = True
        return
    seen[h][w] = True
    memo[h][w] = a
    for dh,dw in [(-1,0),(1,0),(0,1),(0,-1)]:
        nh = h + dh
        nw = w + dw
        if check(nh,nw) and not seen[nh][nw] and A[nh][nw] < a:
            dfs(nh,nw,a + A[nh][nw])
            seen[nh][nw] = False
        if check(nh,nw) and seen[nh][nw] and memo[nh][nw] < a:
            dfs(nh,nw,a)
dfs(Y-1,X-1,A[Y-1][X-1])
if ans:
    print('Yes')
else:
    print('No')


0