結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 👑 rin204rin204
提出日時 2022-05-20 21:53:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 81,672 KB
実行使用メモリ 82,904 KB
最終ジャッジ日時 2023-10-20 12:27:33
合計ジャッジ時間 4,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,436 KB
testcase_01 AC 41 ms
53,436 KB
testcase_02 AC 40 ms
53,436 KB
testcase_03 AC 40 ms
53,436 KB
testcase_04 AC 40 ms
53,436 KB
testcase_05 AC 40 ms
53,436 KB
testcase_06 AC 40 ms
53,436 KB
testcase_07 AC 122 ms
78,104 KB
testcase_08 AC 107 ms
80,368 KB
testcase_09 AC 126 ms
80,464 KB
testcase_10 AC 123 ms
80,940 KB
testcase_11 AC 129 ms
81,400 KB
testcase_12 AC 133 ms
82,772 KB
testcase_13 AC 139 ms
82,904 KB
testcase_14 AC 144 ms
82,828 KB
testcase_15 AC 119 ms
82,172 KB
testcase_16 AC 42 ms
53,452 KB
testcase_17 AC 52 ms
57,548 KB
testcase_18 AC 42 ms
53,452 KB
testcase_19 AC 41 ms
53,452 KB
testcase_20 AC 146 ms
82,304 KB
testcase_21 AC 155 ms
82,640 KB
testcase_22 AC 101 ms
77,428 KB
testcase_23 AC 100 ms
77,396 KB
testcase_24 AC 127 ms
82,260 KB
testcase_25 AC 137 ms
82,488 KB
testcase_26 AC 149 ms
82,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]
dp = [[0] * w for _ in range(h)]
dp2 = [[0] * w for _ in range(h)]
dp[0][0] = A[0][0]
dp2[0][0] = A[0][0]
for i in range(h):
    for j in range(w):
        if i == h - 1 and j == w - 1:
            break
        if i != 0:
            dp2[i][j] = max(dp2[i][j], dp[i - 1][j])
            if A[i][j] < dp[i - 1][j]:
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + A[i][j])
            if A[i][j] < dp2[i - 1][j]:
                dp2[i][j] = max(dp2[i][j], dp2[i - 1][j] + A[i][j])
        if j != 0:
            dp2[i][j] = max(dp2[i][j], dp[i][j - 1])
            if A[i][j] < dp[i][j - 1]:
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + A[i][j])
            if A[i][j] < dp2[i][j - 1]:
                dp2[i][j] = max(dp2[i][j], dp2[i][j - 1] + A[i][j])

if max(dp2[-1][-2], dp2[-2][-1]) > A[-1][-1]:
    print("Yes")
else:
    print("No")
0