結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー hir355hir355
提出日時 2022-05-20 22:09:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 81,596 KB
実行使用メモリ 82,372 KB
最終ジャッジ日時 2023-10-20 12:51:32
合計ジャッジ時間 4,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,452 KB
testcase_01 AC 37 ms
53,452 KB
testcase_02 AC 38 ms
53,452 KB
testcase_03 AC 39 ms
53,452 KB
testcase_04 AC 37 ms
53,452 KB
testcase_05 AC 37 ms
53,452 KB
testcase_06 AC 38 ms
53,452 KB
testcase_07 AC 98 ms
77,448 KB
testcase_08 AC 94 ms
80,160 KB
testcase_09 AC 107 ms
80,232 KB
testcase_10 AC 99 ms
80,180 KB
testcase_11 AC 108 ms
80,560 KB
testcase_12 AC 104 ms
81,972 KB
testcase_13 AC 114 ms
82,012 KB
testcase_14 AC 116 ms
82,176 KB
testcase_15 AC 104 ms
82,016 KB
testcase_16 AC 39 ms
53,452 KB
testcase_17 AC 46 ms
57,548 KB
testcase_18 AC 38 ms
53,452 KB
testcase_19 AC 38 ms
53,452 KB
testcase_20 AC 117 ms
82,152 KB
testcase_21 AC 117 ms
82,004 KB
testcase_22 AC 90 ms
77,512 KB
testcase_23 AC 91 ms
77,372 KB
testcase_24 AC 94 ms
77,380 KB
testcase_25 AC 117 ms
81,916 KB
testcase_26 AC 120 ms
82,372 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]
for i in range(h):
    for j in range(w):
        if i > 0 and j > 0:
            if max(dp[i - 1][j], dp[i][j - 1]) > a[i][j]:
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j]
            if max(dp2[i - 1][j], dp2[i][j - 1]) > a[i][j]:
                dp2[i][j] = max(max(dp2[i - 1][j], dp2[i][j - 1]) + a[i][j], max(dp[i - 1][j], dp[i][j - 1]))
            else:
                dp2[i][j] = max(dp[i - 1][j], dp[i][j - 1])
        elif i > 0:
            if dp[i - 1][j] > a[i][j]:
                dp[i][j] = dp[i - 1][j] + a[i][j]
            if dp2[i - 1][j] > a[i][j]:
                dp2[i][j] = max(dp2[i - 1][j] + a[i][j], dp[i - 1][j])
            else:
                dp2[i][j] = dp[i - 1][j]
        elif j > 0:
            if dp[i][j - 1] > a[i][j]:
                dp[i][j] = dp[i][j - 1] + a[i][j]
            if dp2[i][j - 1] > a[i][j]:
                dp2[i][j] = max(dp2[i][j - 1] + a[i][j], dp[i][j - 1])
            else:
                dp2[i][j] = dp[i][j - 1]
if dp[-1][-1] > a[-1][-1] or dp2[-1][-1] > a[-1][-1]:
    print('Yes')
else:
    print('No')
0