結果

問題 No.1077 Noelちゃんと星々4
ユーザー takakintakakin
提出日時 2020-06-12 21:53:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 390 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 86,676 KB
実行使用メモリ 155,200 KB
最終ジャッジ日時 2023-09-06 10:17:19
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,868 KB
testcase_01 AC 79 ms
76,056 KB
testcase_02 AC 193 ms
130,408 KB
testcase_03 AC 223 ms
138,152 KB
testcase_04 AC 124 ms
92,576 KB
testcase_05 AC 112 ms
92,160 KB
testcase_06 AC 127 ms
92,816 KB
testcase_07 AC 155 ms
108,028 KB
testcase_08 AC 128 ms
92,376 KB
testcase_09 AC 122 ms
92,720 KB
testcase_10 AC 228 ms
138,344 KB
testcase_11 AC 176 ms
115,504 KB
testcase_12 AC 161 ms
113,728 KB
testcase_13 AC 115 ms
91,552 KB
testcase_14 AC 228 ms
138,548 KB
testcase_15 AC 160 ms
112,540 KB
testcase_16 AC 124 ms
92,816 KB
testcase_17 AC 168 ms
115,708 KB
testcase_18 AC 228 ms
138,576 KB
testcase_19 AC 109 ms
90,564 KB
testcase_20 AC 67 ms
75,940 KB
testcase_21 AC 254 ms
155,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
Y=[int(i) for i in input().split()]
DP=[[0]*(10**4+1) for _ in range(n+1)]
for i,y in enumerate(Y):
  m=DP[i][0]
  for j in range(10**4+1):
    if i==0:
      DP[i+1][j]=abs(j-y)
    else:
      if j==0:
        DP[i+1][j]=DP[i][0]+y
      else:
        m=min(DP[i][j],m)
        DP[i+1][j]=m+abs(j-y)
print(min(DP[n]))
0