結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー Akijin_007Akijin_007
提出日時 2022-05-20 23:25:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 100,536 KB
最終ジャッジ日時 2023-10-20 14:21:00
合計ジャッジ時間 4,551 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,472 KB
testcase_01 AC 35 ms
53,472 KB
testcase_02 AC 34 ms
53,472 KB
testcase_03 AC 33 ms
53,472 KB
testcase_04 AC 34 ms
53,472 KB
testcase_05 AC 32 ms
53,472 KB
testcase_06 AC 32 ms
53,472 KB
testcase_07 AC 120 ms
93,824 KB
testcase_08 AC 123 ms
99,528 KB
testcase_09 AC 139 ms
100,112 KB
testcase_10 AC 121 ms
99,568 KB
testcase_11 AC 144 ms
100,352 KB
testcase_12 AC 140 ms
100,156 KB
testcase_13 AC 142 ms
100,096 KB
testcase_14 AC 146 ms
100,212 KB
testcase_15 AC 130 ms
100,028 KB
testcase_16 AC 36 ms
55,520 KB
testcase_17 AC 43 ms
57,568 KB
testcase_18 AC 40 ms
53,472 KB
testcase_19 AC 33 ms
53,472 KB
testcase_20 AC 163 ms
100,088 KB
testcase_21 AC 147 ms
100,028 KB
testcase_22 AC 106 ms
91,524 KB
testcase_23 AC 105 ms
91,556 KB
testcase_24 AC 136 ms
91,836 KB
testcase_25 AC 142 ms
99,152 KB
testcase_26 AC 157 ms
100,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

H, W = map(int, input().split())

A = [0] * H
for i in range(H):
    A[i] = list(map(int, input().split()))

dp = [[[0] * 2 for i in range(W)] for i in range(H)]

dp[1][0][0] = A[0][0]
dp[0][1][0] = A[0][0]

for i in range(H):
    for j in range(W):
        if dp[i][j][0] > A[i][j]:
            if i + 1 < H:
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0] + A[i][j])
            if j + 1 < W:
                dp[i][j+1][0] = max(dp[i][j+1][0], dp[i][j][0] + A[i][j])
        else:
            if i + 1 < H:
                dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][0])
            if j + 1 < W:
                dp[i][j+1][1] = max(dp[i][j+1][1], dp[i][j][0])
        if dp[i][j][1] > A[i][j]:
            if i + 1 < H:
                dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][1] + A[i][j])
            if j + 1 < W:
                dp[i][j+1][1] = max(dp[i][j+1][1], dp[i][j][1] + A[i][j])

f = 0

for i in range(2):
    if dp[H-1][W-1][i] > A[H-1][W-1]:
        f = 1

# for i in range(H):
#     print(dp[i])

if f:
    print("Yes")
else:
    print("No")

0