結果

問題 No.838 Noelちゃんと星々3
ユーザー totori_nyaatotori_nyaa
提出日時 2019-08-06 20:42:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 168,336 KB
実行使用メモリ 7,452 KB
最終ジャッジ日時 2023-09-25 18:12:55
合計ジャッジ時間 3,290 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
7,452 KB
testcase_01 AC 25 ms
7,384 KB
testcase_02 AC 25 ms
7,232 KB
testcase_03 AC 24 ms
7,292 KB
testcase_04 AC 26 ms
7,308 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

 
signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);

    ll n;
    cin>>n;
    ll h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h,h+n);
    ll dp[n+1][4]={};
    dp[0][1]=1e18;
    
    
    for(int i=0;i<n;i++){
        dp[i+1][0] = dp[i][1];
        if(i+1<n) dp[i+1][1] = min(dp[i][0],dp[i][2]) + h[i+1]-h[i];
        if(i) dp[i+1][2] = min(dp[i][0],dp[i][3]) + h[i]-h[i-1];
        else dp[i+1][2] = 1e18;
        dp[i+1][3] = min(dp[i][0],min(dp[i][1],dp[i][2]));
        //cerr<<i<<" "<<dp[i+1][0]<<" "<<dp[i+1][1]<<" "<<dp[i+1][2]<<" "<<dp[i+1][3]<<endl;
    }
    ll ans = min(dp[n][0],dp[n][2]);
    //cerr<<dp[n][0]<<" "<<dp[n][2]<<endl;
    cout<<ans<<endl;


    
}
0