結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー kept1994kept1994
提出日時 2022-10-30 17:26:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,595 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 101,544 KB
最終ジャッジ日時 2023-09-21 15:04:45
合計ジャッジ時間 6,084 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,128 KB
testcase_01 AC 67 ms
71,036 KB
testcase_02 AC 69 ms
71,364 KB
testcase_03 AC 68 ms
71,244 KB
testcase_04 AC 69 ms
71,484 KB
testcase_05 AC 68 ms
71,260 KB
testcase_06 AC 68 ms
71,348 KB
testcase_07 AC 188 ms
101,516 KB
testcase_08 AC 175 ms
101,296 KB
testcase_09 AC 198 ms
101,428 KB
testcase_10 AC 175 ms
101,424 KB
testcase_11 AC 195 ms
101,544 KB
testcase_12 AC 196 ms
101,500 KB
testcase_13 AC 196 ms
101,440 KB
testcase_14 AC 193 ms
101,512 KB
testcase_15 AC 182 ms
101,480 KB
testcase_16 AC 78 ms
75,936 KB
testcase_17 AC 86 ms
75,984 KB
testcase_18 AC 71 ms
71,428 KB
testcase_19 AC 71 ms
71,292 KB
testcase_20 AC 202 ms
101,312 KB
testcase_21 AC 203 ms
101,092 KB
testcase_22 AC 170 ms
101,204 KB
testcase_23 AC 170 ms
101,148 KB
testcase_24 AC 175 ms
101,144 KB
testcase_25 AC 190 ms
100,284 KB
testcase_26 AC 198 ms
101,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    H, W = map(int, input().split())
    G = []
    dp = [[[0] * 2 for _ in range(W) ] for _ in range(H)]
    for _ in range(H):
        G.append(list(map(int, input().split())))
    dp[0][0][0] = G[0][0]

    for hh in range(H):
        for ww in range(W):
            for i in range(2):
                # 横
                if ww + 1 < W:
                    # 勝利
                    if G[hh][ww + 1] < dp[hh][ww][i]:
                        dp[hh][ww + 1][i] = max(dp[hh][ww + 1][i], dp[hh][ww][i] + G[hh][ww + 1])
                    else:
                        # continue
                        if i == 0 and not (hh == H - 1 and ww + 1 == W - 1):
                            dp[hh][ww + 1][1] = max(dp[hh][ww + 1][1], dp[hh][ww][0])
                        # 敗北
                        else:
                            pass 
                # 縦
                if hh + 1 < H:
                    # 勝利
                    if G[hh + 1][ww] < dp[hh][ww][i]:
                        dp[hh + 1][ww][i] = max(dp[hh + 1][ww][i], dp[hh][ww][i] + G[hh + 1][ww])
                    else:
                        # continue
                        if i == 0 and not (hh + 1 == H - 1 and ww == W - 1):
                            dp[hh + 1][ww][1] = max(dp[hh + 1][ww][1], dp[hh][ww][0])
                        # 敗北
                        else:
                            pass 
    if dp[-1][-1][0] > 0 or  dp[-1][-1][1] > 0:
        print("Yes")
    else:
        print("No")
    return


if __name__ == '__main__':
    main()
0