結果

問題 No.1077 Noelちゃんと星々4
ユーザー uni_pythonuni_python
提出日時 2020-06-15 23:49:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,372 KB
実行使用メモリ 155,760 KB
最終ジャッジ日時 2023-09-16 10:41:44
合計ジャッジ時間 5,766 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
75,772 KB
testcase_01 AC 81 ms
75,944 KB
testcase_02 AC 262 ms
131,236 KB
testcase_03 AC 305 ms
146,872 KB
testcase_04 AC 148 ms
98,276 KB
testcase_05 AC 131 ms
91,980 KB
testcase_06 AC 174 ms
104,272 KB
testcase_07 AC 184 ms
108,696 KB
testcase_08 AC 159 ms
99,892 KB
testcase_09 AC 148 ms
96,816 KB
testcase_10 AC 307 ms
147,052 KB
testcase_11 AC 228 ms
122,308 KB
testcase_12 AC 205 ms
114,564 KB
testcase_13 AC 132 ms
91,544 KB
testcase_14 AC 306 ms
145,472 KB
testcase_15 AC 199 ms
113,080 KB
testcase_16 AC 158 ms
100,380 KB
testcase_17 AC 213 ms
118,068 KB
testcase_18 AC 307 ms
148,552 KB
testcase_19 AC 128 ms
90,820 KB
testcase_20 AC 77 ms
75,892 KB
testcase_21 AC 330 ms
155,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    N=I()
    Y=LI()
    inf=10**10
    M=10**4
    dp=[[inf]*(M+1)for _ in range(N+1)]
    #dp[i][j]はi個まで見て,最後の高さがjの時の時の最小値
    #dp[i][j]はdp[i-1][0~j]のmin+cost
    dp[0][0]=0
    

    
    for i in range(N):
        Min=[inf]*(M+1)
        Min[0]=dp[i][0]
        for j in range(M):
            Min[j+1]=min(Min[j],dp[i][j+1])
        
        for j in range(M):
            dp[i+1][j]=Min[j]+abs(Y[i]-j)
            
    ans=inf
    for j in range(M+1):
        ans=min(ans,dp[-1][j])
    print(ans)
    

            
            
    


main()
0