結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー tnodinotnodino
提出日時 2022-05-21 19:41:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 82,984 KB
最終ジャッジ日時 2023-10-20 16:35:25
合計ジャッジ時間 3,987 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,588 KB
testcase_01 AC 38 ms
53,588 KB
testcase_02 AC 36 ms
53,588 KB
testcase_03 AC 36 ms
53,588 KB
testcase_04 AC 35 ms
53,588 KB
testcase_05 AC 35 ms
53,588 KB
testcase_06 AC 35 ms
53,588 KB
testcase_07 AC 97 ms
77,632 KB
testcase_08 AC 98 ms
80,428 KB
testcase_09 AC 108 ms
80,524 KB
testcase_10 AC 99 ms
80,472 KB
testcase_11 AC 115 ms
81,416 KB
testcase_12 AC 112 ms
82,304 KB
testcase_13 AC 128 ms
82,932 KB
testcase_14 AC 128 ms
82,984 KB
testcase_15 AC 104 ms
82,100 KB
testcase_16 AC 38 ms
53,588 KB
testcase_17 AC 46 ms
57,684 KB
testcase_18 AC 37 ms
53,588 KB
testcase_19 AC 36 ms
53,588 KB
testcase_20 AC 131 ms
82,408 KB
testcase_21 AC 126 ms
82,084 KB
testcase_22 AC 91 ms
77,712 KB
testcase_23 AC 88 ms
77,476 KB
testcase_24 AC 96 ms
77,540 KB
testcase_25 AC 113 ms
81,956 KB
testcase_26 AC 124 ms
82,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
DP1 = [[-1] * W for _ in range(H)]
DP2 = [[-1] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            DP1[0][0] = A[0][0]
            continue
        if i - 1 >= 0:
            if DP1[i-1][j] > A[i][j]:
                DP1[i][j] = max(DP1[i][j], DP1[i-1][j] + A[i][j])
            else:
                DP2[i][j] = max(DP2[i][j], DP1[i-1][j])
            if DP2[i-1][j] > A[i][j]:
                DP2[i][j] = max(DP2[i][j], DP2[i-1][j] + A[i][j])
        if j - 1 >= 0:
            if DP1[i][j-1] > A[i][j]:
                DP1[i][j] = max(DP1[i][j], DP1[i][j-1] + A[i][j])
            else:
                DP2[i][j] = max(DP2[i][j], DP1[i][j-1])
            if DP2[i][j-1] > A[i][j]:
                DP2[i][j] = max(DP2[i][j], DP2[i][j-1] + A[i][j])
if DP1[-1][-1] > A[-1][-1] or DP2[-1][-1] > A[-1][-1]:
    print('Yes')
else:
    print('No')
0