結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー rlangevinrlangevin
提出日時 2023-01-10 23:34:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,153 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 84,544 KB
最終ジャッジ日時 2023-08-23 10:30:40
合計ジャッジ時間 6,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,192 KB
testcase_01 AC 72 ms
71,408 KB
testcase_02 AC 73 ms
71,500 KB
testcase_03 AC 71 ms
71,160 KB
testcase_04 AC 72 ms
71,312 KB
testcase_05 AC 72 ms
71,272 KB
testcase_06 AC 72 ms
71,160 KB
testcase_07 AC 151 ms
83,532 KB
testcase_08 AC 138 ms
80,196 KB
testcase_09 AC 154 ms
80,976 KB
testcase_10 AC 136 ms
80,320 KB
testcase_11 AC 158 ms
81,232 KB
testcase_12 AC 159 ms
84,096 KB
testcase_13 AC 178 ms
84,544 KB
testcase_14 AC 167 ms
84,248 KB
testcase_15 AC 148 ms
83,524 KB
testcase_16 AC 75 ms
71,404 KB
testcase_17 AC 82 ms
71,364 KB
testcase_18 AC 73 ms
71,316 KB
testcase_19 AC 73 ms
71,272 KB
testcase_20 AC 174 ms
84,540 KB
testcase_21 AC 159 ms
83,784 KB
testcase_22 AC 135 ms
83,324 KB
testcase_23 AC 134 ms
83,524 KB
testcase_24 AC 131 ms
78,692 KB
testcase_25 AC 152 ms
83,612 KB
testcase_26 AC 162 ms
82,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
    
inf = 10 ** 18
dp0 = [[-inf] * W for i in range(H)]
dp1 = [[-inf] * W for i in range(H)]
dp0[0][0] = A[0][0]
for i in range(H):
    for j in range(W):
        if i != H - 1:
            if A[i + 1][j] < dp0[i][j]:
                dp0[i + 1][j] = max(dp0[i + 1][j],  dp0[i][j] + A[i + 1][j])
            else:
                if (i + 1, j) != (H - 1, W - 1):
                    dp1[i + 1][j] = max(dp1[i + 1][j], dp0[i][j])
            if A[i + 1][j] < dp1[i][j]:
                dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j] + A[i + 1][j])
        if j != W - 1:
            if A[i][j + 1] < dp0[i][j]:
                dp0[i][j + 1] = max(dp0[i][j + 1], dp0[i][j] + A[i][j + 1])
            else:
                if (i, j + 1) != (H - 1, W - 1):
                    dp1[i][j + 1] = max(dp1[i][j + 1], dp0[i][j])
            if A[i][j + 1] < dp1[i][j]:
                dp1[i][j + 1] = max(dp1[i][j + 1], dp1[i][j] + A[i][j + 1])
ans = max(dp0[-1][-1], dp1[-1][-1])
print("Yes") if ans > 0 else print("No")
# print(dp0)
# print(dp1)
            
0