結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー lilictakalilictaka
提出日時 2022-05-20 23:13:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 1,035 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 81,608 KB
実行使用メモリ 92,236 KB
最終ジャッジ日時 2023-10-20 14:06:24
合計ジャッジ時間 4,330 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,396 KB
testcase_01 AC 38 ms
53,396 KB
testcase_02 AC 39 ms
53,396 KB
testcase_03 AC 39 ms
53,396 KB
testcase_04 AC 38 ms
53,396 KB
testcase_05 AC 38 ms
53,396 KB
testcase_06 AC 37 ms
53,396 KB
testcase_07 AC 119 ms
81,788 KB
testcase_08 AC 103 ms
81,716 KB
testcase_09 AC 131 ms
84,144 KB
testcase_10 AC 139 ms
87,744 KB
testcase_11 AC 138 ms
85,828 KB
testcase_12 AC 137 ms
83,956 KB
testcase_13 AC 146 ms
84,364 KB
testcase_14 AC 142 ms
84,176 KB
testcase_15 AC 121 ms
83,572 KB
testcase_16 AC 47 ms
62,036 KB
testcase_17 AC 53 ms
64,048 KB
testcase_18 AC 39 ms
53,396 KB
testcase_19 AC 38 ms
53,396 KB
testcase_20 AC 163 ms
84,164 KB
testcase_21 AC 154 ms
84,468 KB
testcase_22 AC 114 ms
84,552 KB
testcase_23 AC 99 ms
81,808 KB
testcase_24 AC 137 ms
84,448 KB
testcase_25 AC 165 ms
92,236 KB
testcase_26 AC 172 ms
91,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int,input().split())
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
INF = float('inf')
dp0 = [[-INF] * W for _ in range(H)]
dp1 = [[-INF] * W for _ in range(H)]
dp0[0][0] = A[0][0]
for h in range(H):
    for w in range(W):
        for dh,dw in [(1,0),(0,1)]:
            nh = h + dh
            nw = w + dw
            if dp0[h][w] != -INF:
                if check(nh,nw) and A[nh][nw] < dp0[h][w]:
                    dp0[nh][nw] = max(dp0[h][w] + A[nh][nw] ,dp0[nh][nw])
                elif check(nh,nw) and A[nh][nw] >= dp0[h][w] and not (nh == H-1 and nw == W-1):
                    dp1[nh][nw] = max(dp0[h][w],dp1[nh][nw])
            if dp1[h][w] != -INF:
                if check(nh,nw) and A[nh][nw] < dp1[h][w]:
                    dp1[nh][nw] = max(dp1[h][w] + A[nh][nw],dp1[nh][nw])
if dp0[H-1][W-1] != -INF or dp1[H-1][W-1] != -INF:
    print('Yes')
else:
    print('No')
0