結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー lilictakalilictaka
提出日時 2022-05-20 23:37:27
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 849 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 128,980 KB
最終ジャッジ日時 2023-10-20 14:33:38
合計ジャッジ時間 10,769 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,620 KB
testcase_01 AC 38 ms
53,564 KB
testcase_02 AC 39 ms
53,564 KB
testcase_03 AC 39 ms
53,564 KB
testcase_04 AC 38 ms
53,564 KB
testcase_05 AC 40 ms
53,564 KB
testcase_06 AC 39 ms
53,564 KB
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 80 ms
80,572 KB
testcase_17 RE -
testcase_18 AC 82 ms
80,576 KB
testcase_19 AC 41 ms
53,564 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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