結果

問題 No.838 Noelちゃんと星々3
ユーザー hedwig100hedwig100
提出日時 2020-04-19 14:22:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,536 KB
最終ジャッジ日時 2024-04-15 12:34:51
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
22,476 KB
testcase_01 AC 191 ms
22,508 KB
testcase_02 AC 187 ms
22,480 KB
testcase_03 AC 190 ms
22,536 KB
testcase_04 AC 187 ms
22,472 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 31 ms
10,752 KB
testcase_14 AC 31 ms
10,752 KB
testcase_15 AC 31 ms
10,752 KB
testcase_16 AC 31 ms
10,752 KB
testcase_17 AC 32 ms
10,880 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 30 ms
10,752 KB
testcase_20 AC 31 ms
10,752 KB
testcase_21 AC 31 ms
10,752 KB
testcase_22 AC 30 ms
10,880 KB
testcase_23 AC 31 ms
10,752 KB
testcase_24 AC 31 ms
10,880 KB
testcase_25 AC 31 ms
10,880 KB
testcase_26 AC 30 ms
10,752 KB
testcase_27 AC 31 ms
10,752 KB
testcase_28 AC 30 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n = int(input())
    Y = list(map(int,input().split()))
    Y.sort()
    
    dp0 = [0] * (n + 1)
    dp1 = [0] * (n + 1)
    dp0[2] = Y[1] - Y[0]
    dp1[2] = Y[1] - Y[0]
    for i in range(2,n):
        if i > 2:
            dp0[i + 1] = min(dp0[i - 1],dp1[i - 1]) + Y[i] - Y[i - 1]
            dp1[i + 1] = dp0[i] + Y[i] - Y[i - 1]
        if i == 2:
            dp0[i + 1] = 2 * Y[2] - Y[1] - Y[0]
            dp1[i + 1] = Y[2] - Y[0]

    print(min(dp0[-1],dp1[-1]))

if __name__ == '__main__':
    main()
0