結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 👑 KazunKazun
提出日時 2022-05-20 21:54:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 81,688 KB
実行使用メモリ 112,956 KB
最終ジャッジ日時 2023-10-20 12:27:41
合計ジャッジ時間 4,816 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,448 KB
testcase_01 AC 42 ms
53,448 KB
testcase_02 AC 40 ms
53,448 KB
testcase_03 AC 38 ms
53,448 KB
testcase_04 AC 39 ms
53,448 KB
testcase_05 AC 38 ms
53,448 KB
testcase_06 AC 39 ms
53,448 KB
testcase_07 AC 182 ms
106,672 KB
testcase_08 AC 140 ms
98,300 KB
testcase_09 AC 156 ms
98,952 KB
testcase_10 AC 144 ms
98,328 KB
testcase_11 AC 168 ms
99,472 KB
testcase_12 AC 184 ms
101,256 KB
testcase_13 AC 202 ms
102,456 KB
testcase_14 AC 202 ms
102,268 KB
testcase_15 AC 166 ms
100,980 KB
testcase_16 AC 43 ms
59,096 KB
testcase_17 AC 52 ms
63,192 KB
testcase_18 AC 39 ms
53,448 KB
testcase_19 AC 37 ms
53,448 KB
testcase_20 AC 211 ms
112,956 KB
testcase_21 AC 210 ms
112,428 KB
testcase_22 AC 129 ms
88,168 KB
testcase_23 AC 144 ms
100,284 KB
testcase_24 AC 164 ms
107,860 KB
testcase_25 AC 152 ms
102,640 KB
testcase_26 AC 159 ms
100,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

A=["*"]
for _ in range(H):
    A.append(["*"]+list(map(int,input().split())))

inf=float("inf"); huge=2*10**9
DP=[[[-inf,-inf] for _ in range(W+1)] for _ in range(H+1)]

for i in range(1,H+1):
    for j in range(1,W+1):
        if i==j==1:
            DP[i][j]=[A[1][1],-inf]
            continue

        if max(DP[i-1][j][0],DP[i][j-1][0])>A[i][j]:
            DP[i][j][0]=max(DP[i-1][j][0],DP[i][j-1][0])+A[i][j]
        else:
            DP[i][j][1]=max(DP[i-1][j][0],DP[i][j-1][0])

        if max(DP[i-1][j][1],DP[i][j-1][1])>A[i][j]:
            DP[i][j][1]=max(DP[i][j][1], max(DP[i-1][j][1],DP[i][j-1][1])+A[i][j])

        if DP[i][j][0]>huge:
            DP[i][j][0]=inf

        if DP[i][j][1]>huge:
            DP[i][j][1]=inf

if max(DP[H-1][W][0], DP[H-1][W][1], DP[H][W-1][0], DP[H][W-1][1])>A[H][W]:
    print("Yes")
else:
    print("No")
0