結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー hashi_pyhashi_py
提出日時 2022-05-21 01:23:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2023-10-20 15:25:34
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,588 KB
testcase_01 AC 36 ms
53,588 KB
testcase_02 AC 44 ms
53,588 KB
testcase_03 AC 37 ms
53,588 KB
testcase_04 AC 37 ms
53,588 KB
testcase_05 AC 37 ms
53,588 KB
testcase_06 AC 37 ms
53,588 KB
testcase_07 AC 101 ms
77,564 KB
testcase_08 AC 95 ms
77,968 KB
testcase_09 AC 109 ms
78,028 KB
testcase_10 AC 107 ms
78,044 KB
testcase_11 AC 117 ms
78,732 KB
testcase_12 AC 116 ms
82,872 KB
testcase_13 AC 132 ms
83,072 KB
testcase_14 AC 122 ms
82,924 KB
testcase_15 AC 103 ms
82,188 KB
testcase_16 AC 41 ms
55,636 KB
testcase_17 AC 48 ms
57,684 KB
testcase_18 AC 38 ms
53,588 KB
testcase_19 AC 38 ms
53,588 KB
testcase_20 AC 123 ms
82,772 KB
testcase_21 AC 119 ms
82,308 KB
testcase_22 AC 92 ms
77,488 KB
testcase_23 AC 91 ms
77,460 KB
testcase_24 AC 104 ms
82,352 KB
testcase_25 AC 113 ms
80,088 KB
testcase_26 AC 123 ms
78,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
G = [list(map(int,input().split()))+[0] for _ in range(h)]
G.append([0]*(w+1))
dpA = [[0]*(w+1) for _ in range(h+1)]
dpB = [[0]*(w+1) for _ in range(h+1)]
dpA[0][0]=G[0][0]
dpB[0][0]=G[0][0]

for i in range(h):
    for j in range(w):
        if(G[i+1][j]<dpA[i][j]):
            dpA[i+1][j]=max(dpA[i+1][j],dpA[i][j]+G[i+1][j])
        else:
            dpB[i+1][j]=max(dpB[i+1][j],dpA[i][j])

        if(G[i][j+1]<dpA[i][j]):
            dpA[i][j+1]=max(dpA[i][j+1],dpA[i][j]+G[i][j+1])
        else:
            dpB[i][j+1]=max(dpB[i][j+1],dpA[i][j])

        if(G[i+1][j]<dpB[i][j]):
            dpB[i+1][j]=max(dpB[i+1][j],dpB[i][j]+G[i+1][j])
        if(G[i][j+1]<dpB[i][j]):
            dpB[i][j+1]=max(dpB[i][j+1],dpB[i][j]+G[i][j+1])

if(dpA[-2][-2]>G[-2][-2] or dpB[-2][-2]>G[-2][-2]):
    print("Yes")
else:
    print("No")
0