結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー hir355hir355
提出日時 2022-05-20 22:08:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,268 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,548 KB
実行使用メモリ 82,324 KB
最終ジャッジ日時 2023-10-20 12:49:44
合計ジャッジ時間 3,978 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,420 KB
testcase_01 AC 36 ms
53,420 KB
testcase_02 AC 36 ms
53,420 KB
testcase_03 AC 38 ms
53,420 KB
testcase_04 AC 38 ms
53,420 KB
testcase_05 AC 37 ms
53,420 KB
testcase_06 AC 37 ms
53,420 KB
testcase_07 AC 94 ms
77,368 KB
testcase_08 AC 91 ms
80,080 KB
testcase_09 WA -
testcase_10 AC 101 ms
80,092 KB
testcase_11 AC 105 ms
80,484 KB
testcase_12 AC 105 ms
81,880 KB
testcase_13 AC 114 ms
81,924 KB
testcase_14 AC 118 ms
82,100 KB
testcase_15 AC 100 ms
81,948 KB
testcase_16 AC 39 ms
53,420 KB
testcase_17 AC 45 ms
57,516 KB
testcase_18 AC 37 ms
53,420 KB
testcase_19 AC 38 ms
53,420 KB
testcase_20 AC 117 ms
81,932 KB
testcase_21 AC 113 ms
81,928 KB
testcase_22 AC 90 ms
77,440 KB
testcase_23 WA -
testcase_24 AC 93 ms
77,280 KB
testcase_25 AC 116 ms
81,844 KB
testcase_26 AC 119 ms
82,324 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 dp[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 dp[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