結果

問題 No.838 Noelちゃんと星々3
ユーザー pluto77pluto77
提出日時 2019-06-19 09:59:39
言語 Python2
(2.7.18)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 286 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 14,992 KB
最終ジャッジ日時 2024-05-07 14:32:13
合計ジャッジ時間 2,359 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
14,868 KB
testcase_01 AC 148 ms
14,992 KB
testcase_02 AC 150 ms
14,736 KB
testcase_03 AC 146 ms
14,832 KB
testcase_04 AC 144 ms
14,864 KB
testcase_05 AC 10 ms
7,168 KB
testcase_06 AC 10 ms
6,912 KB
testcase_07 AC 11 ms
7,040 KB
testcase_08 AC 10 ms
6,912 KB
testcase_09 AC 10 ms
7,040 KB
testcase_10 AC 11 ms
6,912 KB
testcase_11 AC 10 ms
7,040 KB
testcase_12 AC 10 ms
7,040 KB
testcase_13 AC 10 ms
7,040 KB
testcase_14 AC 10 ms
6,912 KB
testcase_15 AC 11 ms
7,040 KB
testcase_16 AC 10 ms
7,040 KB
testcase_17 AC 11 ms
7,040 KB
testcase_18 AC 11 ms
7,168 KB
testcase_19 AC 11 ms
6,912 KB
testcase_20 AC 11 ms
7,168 KB
testcase_21 AC 10 ms
7,040 KB
testcase_22 AC 11 ms
7,168 KB
testcase_23 AC 10 ms
7,040 KB
testcase_24 AC 10 ms
7,040 KB
testcase_25 AC 11 ms
7,040 KB
testcase_26 AC 11 ms
7,168 KB
testcase_27 AC 12 ms
6,912 KB
testcase_28 AC 12 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki838

n=int(raw_input())
y=map(int,raw_input().split())

y.sort()
dp=[0]*100001
if n==2:
 res=y[1]-y[0]
elif y==3:
 res=y[2]-y[0]
else:
 dp[0]=10**9
 dp[1]=y[1]-y[0]
 dp[2]=y[2]-y[0]
 for i in xrange(3,n):
  dp[i]=min(y[i]-y[i-2]+dp[i-3],y[i]-y[i-1]+dp[i-2])
 res=dp[n-1]
print res
0