結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー lilictakalilictaka
提出日時 2022-05-20 23:42:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 855 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 25,192 KB
最終ジャッジ日時 2023-10-20 14:38:46
合計ジャッジ時間 3,708 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,164 KB
testcase_01 AC 29 ms
10,164 KB
testcase_02 AC 28 ms
10,164 KB
testcase_03 AC 28 ms
10,164 KB
testcase_04 AC 29 ms
10,164 KB
testcase_05 AC 28 ms
10,164 KB
testcase_06 AC 28 ms
10,164 KB
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 91 ms
16,608 KB
testcase_17 RE -
testcase_18 AC 91 ms
16,648 KB
testcase_19 AC 28 ms
10,164 KB
testcase_20 RE -
testcase_21 AC 32 ms
10,332 KB
testcase_22 RE -
testcase_23 AC 29 ms
10,180 KB
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

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:
        print('Yes')
        exit()
    seen[h][w] = True
    if memo[h][w] >= a:
        return 
    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])
print('No')

0