結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー pitPpitP
提出日時 2022-05-21 13:09:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 83,172 KB
最終ジャッジ日時 2023-10-20 16:04:43
合計ジャッジ時間 4,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,520 KB
testcase_01 AC 37 ms
53,520 KB
testcase_02 AC 37 ms
53,520 KB
testcase_03 AC 37 ms
53,520 KB
testcase_04 AC 37 ms
53,520 KB
testcase_05 AC 37 ms
53,520 KB
testcase_06 AC 37 ms
53,520 KB
testcase_07 AC 125 ms
82,252 KB
testcase_08 AC 109 ms
79,688 KB
testcase_09 AC 130 ms
80,336 KB
testcase_10 AC 111 ms
79,692 KB
testcase_11 AC 133 ms
80,408 KB
testcase_12 AC 130 ms
82,712 KB
testcase_13 AC 145 ms
83,096 KB
testcase_14 AC 153 ms
83,172 KB
testcase_15 AC 125 ms
82,956 KB
testcase_16 AC 43 ms
58,952 KB
testcase_17 AC 51 ms
63,148 KB
testcase_18 AC 39 ms
53,520 KB
testcase_19 AC 39 ms
53,520 KB
testcase_20 AC 150 ms
83,140 KB
testcase_21 AC 140 ms
83,052 KB
testcase_22 AC 101 ms
77,488 KB
testcase_23 AC 101 ms
77,680 KB
testcase_24 AC 113 ms
82,540 KB
testcase_25 AC 131 ms
82,548 KB
testcase_26 AC 140 ms
81,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]

dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(2)]
dp[0][0][0] = a[0][0]

for i in range(h):
    for j in range(w):
        if i + 1 < h and dp[0][i][j] > a[i+1][j]:
            dp[0][i+1][j] = max(dp[0][i][j] + a[i+1][j],dp[0][i+1][j])
        elif i + 1 < h:
            dp[1][i+1][j] = max(dp[0][i][j],dp[1][i+1][j])

        if j + 1 < w and dp[0][i][j] > a[i][j+1]:
            dp[0][i][j+1] = max(dp[0][i][j] + a[i][j+1],dp[0][i][j+1])
        elif j + 1 < w:
            dp[1][i][j+1] = max(dp[0][i][j],dp[1][i][j+1])

        
        if i + 1 < h and dp[1][i][j] > a[i+1][j]:
            dp[1][i+1][j] = max(dp[1][i][j] + a[i+1][j],dp[1][i+1][j])
        if j + 1 < w and dp[1][i][j] > a[i][j+1]:
            dp[1][i][j+1] = max(dp[1][i][j] + a[i][j+1],dp[1][i][j+1])


if dp[0][-1][-1] > a[-1][-1] or dp[1][-1][-1] > a[-1][-1]:
    print("Yes")
else:
    print("No")
0