結果

問題 No.838 Noelちゃんと星々3
ユーザー NoneNone
提出日時 2021-03-21 19:56:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 365 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 93,248 KB
最終ジャッジ日時 2023-08-14 16:14:09
合計ジャッジ時間 4,231 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
93,248 KB
testcase_01 AC 127 ms
93,064 KB
testcase_02 AC 122 ms
93,128 KB
testcase_03 AC 126 ms
93,120 KB
testcase_04 AC 126 ms
93,076 KB
testcase_05 AC 57 ms
71,340 KB
testcase_06 AC 58 ms
71,532 KB
testcase_07 AC 59 ms
71,312 KB
testcase_08 AC 58 ms
71,472 KB
testcase_09 AC 60 ms
71,132 KB
testcase_10 AC 59 ms
71,128 KB
testcase_11 AC 58 ms
71,176 KB
testcase_12 AC 58 ms
71,120 KB
testcase_13 AC 60 ms
71,256 KB
testcase_14 AC 60 ms
71,136 KB
testcase_15 AC 57 ms
71,036 KB
testcase_16 AC 57 ms
71,464 KB
testcase_17 AC 59 ms
71,528 KB
testcase_18 AC 58 ms
71,312 KB
testcase_19 AC 58 ms
71,316 KB
testcase_20 AC 58 ms
71,456 KB
testcase_21 AC 59 ms
71,116 KB
testcase_22 AC 58 ms
71,188 KB
testcase_23 AC 59 ms
71,264 KB
testcase_24 AC 59 ms
71,544 KB
testcase_25 AC 57 ms
71,256 KB
testcase_26 AC 58 ms
71,308 KB
testcase_27 AC 57 ms
71,184 KB
testcase_28 AC 56 ms
71,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def median(array):
    L = len(array)
    m=array[L//2]
    res=0
    for a in array:
        res+=abs(a-m)
    return res

N=int(input())
Y=list(map(int, input().split()))
Y.sort()
INF=10**18
dp=[INF]*(N+1)
dp[0]=0
for i in range(N-1):
    dp[i+2]=min(dp[i+2],dp[i]+median(Y[i:i+2]))
    if i+3<=N:
        dp[i+3]=min(dp[i+3],dp[i]+median(Y[i:i+3]))
print(dp[-1])
0