結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー abababab
提出日時 2022-05-21 00:10:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,048 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 103,808 KB
最終ジャッジ日時 2023-10-20 15:04:52
合計ジャッジ時間 5,040 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,616 KB
testcase_01 AC 35 ms
53,616 KB
testcase_02 AC 33 ms
53,616 KB
testcase_03 AC 32 ms
53,616 KB
testcase_04 AC 31 ms
53,616 KB
testcase_05 AC 33 ms
53,616 KB
testcase_06 AC 32 ms
53,616 KB
testcase_07 AC 164 ms
103,568 KB
testcase_08 AC 157 ms
103,616 KB
testcase_09 AC 163 ms
103,616 KB
testcase_10 AC 179 ms
103,760 KB
testcase_11 AC 177 ms
103,500 KB
testcase_12 AC 153 ms
103,704 KB
testcase_13 AC 192 ms
103,716 KB
testcase_14 AC 154 ms
103,704 KB
testcase_15 AC 148 ms
103,660 KB
testcase_16 AC 50 ms
64,032 KB
testcase_17 AC 58 ms
68,568 KB
testcase_18 AC 37 ms
53,616 KB
testcase_19 AC 37 ms
53,616 KB
testcase_20 AC 168 ms
103,676 KB
testcase_21 AC 173 ms
103,656 KB
testcase_22 AC 148 ms
103,808 KB
testcase_23 AC 155 ms
103,632 KB
testcase_24 AC 156 ms
103,684 KB
testcase_25 AC 157 ms
102,652 KB
testcase_26 AC 164 ms
103,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

DXY = [(0, 1), (1, 0)]

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

for i in range(h):
    for j in range(w):
        a = dp[i][j][0]
        for di, dj in DXY:
            ni, nj = i + di, j + dj
            if not (0 <= ni < h and 0 <= nj < w):
                continue
            enemy = A[ni][nj]
            if a > enemy:
                dp[ni][nj][0] = max(dp[ni][nj][0], a + enemy)
            else:
                if dp[ni][nj][1]:
                    continue
                dp[ni][nj][1] = max(dp[ni][nj][0], a)

        a = dp[i][j][1]
        for di, dj in DXY:
            ni, nj = i + di, j + dj
            if not (0 <= ni < h and 0 <= nj < w):
                continue
            enemy = A[ni][nj]
            if a > enemy:
                dp[ni][nj][1] = max(dp[ni][nj][1], a + enemy)

if dp[-1][-1][0]:
    print('Yes')
else:
    ans = dp[-1][-1][1]
    print('Yes' if ans and ans > A[-1][-1] else 'No')
0