結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
14,640 KB
testcase_01 AC 174 ms
14,496 KB
testcase_02 AC 170 ms
14,508 KB
testcase_03 AC 172 ms
14,604 KB
testcase_04 AC 171 ms
14,420 KB
testcase_05 AC 13 ms
6,444 KB
testcase_06 AC 14 ms
6,604 KB
testcase_07 AC 13 ms
6,524 KB
testcase_08 AC 13 ms
6,448 KB
testcase_09 AC 13 ms
6,432 KB
testcase_10 AC 13 ms
6,432 KB
testcase_11 AC 13 ms
6,576 KB
testcase_12 AC 13 ms
6,516 KB
testcase_13 AC 13 ms
6,604 KB
testcase_14 AC 13 ms
6,516 KB
testcase_15 AC 13 ms
6,436 KB
testcase_16 AC 13 ms
6,496 KB
testcase_17 AC 13 ms
6,640 KB
testcase_18 AC 13 ms
6,624 KB
testcase_19 AC 13 ms
6,552 KB
testcase_20 AC 12 ms
6,540 KB
testcase_21 AC 13 ms
6,536 KB
testcase_22 AC 13 ms
6,596 KB
testcase_23 AC 13 ms
6,608 KB
testcase_24 AC 13 ms
6,600 KB
testcase_25 AC 13 ms
6,516 KB
testcase_26 AC 13 ms
6,648 KB
testcase_27 AC 13 ms
6,448 KB
testcase_28 AC 12 ms
6,596 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