結果

問題 No.838 Noelちゃんと星々3
ユーザー R ITSUMIR ITSUMI
提出日時 2020-06-22 22:07:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 244 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 94,768 KB
最終ジャッジ日時 2023-09-16 19:29:46
合計ジャッジ時間 3,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
94,768 KB
testcase_01 AC 113 ms
94,488 KB
testcase_02 AC 116 ms
94,692 KB
testcase_03 AC 110 ms
94,492 KB
testcase_04 AC 112 ms
94,480 KB
testcase_05 AC 68 ms
71,460 KB
testcase_06 AC 69 ms
71,360 KB
testcase_07 AC 69 ms
71,544 KB
testcase_08 AC 66 ms
71,504 KB
testcase_09 AC 68 ms
71,296 KB
testcase_10 AC 69 ms
71,460 KB
testcase_11 AC 67 ms
71,404 KB
testcase_12 AC 68 ms
71,148 KB
testcase_13 AC 66 ms
71,436 KB
testcase_14 AC 65 ms
71,344 KB
testcase_15 AC 67 ms
71,540 KB
testcase_16 AC 65 ms
71,632 KB
testcase_17 AC 67 ms
71,580 KB
testcase_18 AC 67 ms
71,280 KB
testcase_19 AC 65 ms
71,472 KB
testcase_20 AC 66 ms
71,352 KB
testcase_21 AC 68 ms
71,356 KB
testcase_22 AC 65 ms
71,400 KB
testcase_23 AC 66 ms
71,360 KB
testcase_24 AC 66 ms
71,456 KB
testcase_25 AC 66 ms
71,296 KB
testcase_26 AC 66 ms
71,296 KB
testcase_27 AC 68 ms
71,136 KB
testcase_28 AC 68 ms
71,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
Y = sorted(list(map(int, input().split())))
dp = [float('inf')]*N
dp[1] = abs(Y[0]-Y[1])
if N > 2:
    dp[2] = abs(Y[0]-Y[2])
for i in range(3,N):
    dp[i] = min(dp[i-3]+abs(Y[i]-Y[i-2]),dp[i-2]+abs(Y[i]-Y[i-1]))
print(dp[-1])
0