結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー KudeKude
提出日時 2022-05-20 22:23:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 101,036 KB
最終ジャッジ日時 2023-10-20 13:08:41
合計ジャッジ時間 5,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,488 KB
testcase_01 AC 39 ms
53,488 KB
testcase_02 AC 37 ms
53,488 KB
testcase_03 AC 37 ms
53,488 KB
testcase_04 AC 38 ms
53,488 KB
testcase_05 AC 37 ms
53,488 KB
testcase_06 AC 37 ms
53,488 KB
testcase_07 AC 142 ms
93,224 KB
testcase_08 AC 131 ms
99,500 KB
testcase_09 AC 156 ms
99,744 KB
testcase_10 AC 147 ms
99,932 KB
testcase_11 AC 159 ms
100,532 KB
testcase_12 AC 155 ms
100,020 KB
testcase_13 AC 173 ms
100,988 KB
testcase_14 AC 167 ms
100,712 KB
testcase_15 AC 143 ms
99,756 KB
testcase_16 AC 39 ms
53,488 KB
testcase_17 AC 46 ms
57,584 KB
testcase_18 AC 40 ms
53,488 KB
testcase_19 AC 38 ms
53,488 KB
testcase_20 AC 188 ms
99,992 KB
testcase_21 AC 170 ms
100,020 KB
testcase_22 AC 115 ms
91,476 KB
testcase_23 AC 113 ms
91,444 KB
testcase_24 AC 139 ms
92,336 KB
testcase_25 AC 166 ms
99,040 KB
testcase_26 AC 180 ms
101,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
INF = 10 ** 9
dp = [[[-INF] * 2 for _ in range(w)] for _ in range(h)]
dp[0][0][0] = a[0][0]
for i in range(h):
    for j in range(w):
        if i + 1 < h:
            if dp[i][j][0] != -INF:
                if dp[i][j][0] > a[i+1][j]:
                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0] + a[i+1][j])
                elif i + 1 != h - 1 or j != w - 1:
                    dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][0])
            if dp[i][j][1] > a[i+1][j]:
                dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][1] + a[i+1][j])
        if j + 1 < w:
            if dp[i][j][0] != -INF:
                if dp[i][j][0] > a[i][j+1]:
                    dp[i][j+1][0] = max(dp[i][j+1][0], dp[i][j][0] + a[i][j+1])
                elif i != h - 1 or j + 1 != w - 1:
                    dp[i][j+1][1] = max(dp[i][j+1][1], dp[i][j][0])
            if dp[i][j][1] > a[i][j+1]:
                dp[i][j+1][1] = max(dp[i][j+1][1], dp[i][j][1] + a[i][j+1])
ans = max(dp[h-1][w-1])
print('Yes' if ans != -INF else 'No')
0