結果

問題 No.1077 Noelちゃんと星々4
ユーザー ayaoniayaoni
提出日時 2021-05-01 16:16:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 253,612 KB
最終ジャッジ日時 2023-09-27 06:10:23
合計ジャッジ時間 7,810 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,852 KB
testcase_01 AC 85 ms
76,124 KB
testcase_02 AC 377 ms
205,780 KB
testcase_03 AC 452 ms
243,848 KB
testcase_04 AC 191 ms
115,880 KB
testcase_05 AC 172 ms
114,176 KB
testcase_06 AC 232 ms
138,676 KB
testcase_07 AC 241 ms
138,728 KB
testcase_08 AC 212 ms
131,588 KB
testcase_09 AC 186 ms
115,796 KB
testcase_10 AC 455 ms
243,876 KB
testcase_11 AC 334 ms
184,692 KB
testcase_12 AC 278 ms
161,440 KB
testcase_13 AC 168 ms
112,440 KB
testcase_14 AC 437 ms
230,388 KB
testcase_15 AC 280 ms
161,692 KB
testcase_16 AC 216 ms
133,420 KB
testcase_17 AC 302 ms
174,740 KB
testcase_18 AC 461 ms
247,268 KB
testcase_19 AC 168 ms
110,848 KB
testcase_20 AC 81 ms
76,132 KB
testcase_21 AC 491 ms
253,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
Y = [0]+LI()

dp = [[0]*12000 for _ in range(N+1)]
min_dp = [[0]*12000 for _ in range(N+1)]
# dp[i][j] = i番目の要素まで見て、最後の要素がjになるときの距離の総和の最小値
# min_dp[i][j] = i番目の要素まで見て、最後の要素がj以下になるときの距離の総和の最小値
for i in range(1,N+1):
    y = Y[i]
    for j in range(12000):
        dp[i][j] = min_dp[i-1][j]+abs(y-j)
        
    min_dp[i][0] = dp[i][0]
    a = dp[i][0]
    for j in range(1,12000):
        a = min(a,dp[i][j])
        min_dp[i][j] = a

ans = min_dp[-1][-1]
print(ans)
0