結果

問題 No.838 Noelちゃんと星々3
ユーザー RubikunRubikun
提出日時 2019-08-05 17:19:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 169,888 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2023-09-25 17:22:35
合計ジャッジ時間 3,924 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
5,472 KB
testcase_01 AC 50 ms
5,416 KB
testcase_02 AC 50 ms
5,468 KB
testcase_03 AC 49 ms
5,380 KB
testcase_04 AC 49 ms
5,436 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,388 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 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;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;
const ll INF=1LL<<50;

int main(){

    int N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    sort(all(A));
    
    ll dp[N+1][2];//j=0のときは2個区切りj=1のときは3個区切り
    
    for(int i=0;i<N+1;i++){
        for(int j=0;j<2;j++){
            dp[i][j]=INF;
        }
    }
    
    dp[0][0]=dp[0][1]=0;
    
    dp[2][0]=A[1]-A[0];
    
    for(int i=3;i<=N;i++){
        dp[i][0]=min(dp[i-2][0],dp[i-2][1])+A[i-1]-A[i-2];
        dp[i][1]=min(dp[i-3][0],dp[i-3][1])+A[i-1]-A[i-3];
    }
    
    cout<<min(dp[N][0],dp[N][1])<<endl;
    
}
0