結果

問題 No.838 Noelちゃんと星々3
ユーザー Y17Y17
提出日時 2019-06-14 22:26:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 160,088 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-26 17:16:44
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
10,368 KB
testcase_01 AC 51 ms
10,496 KB
testcase_02 AC 50 ms
10,496 KB
testcase_03 AC 50 ms
10,368 KB
testcase_04 AC 51 ms
10,496 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

#define INF 100000000000000LL

int n;
int y[100010];

int memo[100010][2];

int dp(int i, int x){
    if(i >= n){
        return 0;
    }
    if(i == n-1){
        if(x == 0){
            return INF;
        }else{
            return 0;
        }
    }

    if(memo[i][x] != -1){
        return memo[i][x];
    }

    if(x == 0){
        return memo[i][x] = dp(i+1, 1) + y[i+1]-y[i];
    }else{
        return memo[i][x] = min(dp(i+2, 0) + y[i+1]-y[i], dp(i+1, 0));
    }
}

signed main(){
    cin >> n;
    for(int i = 0;i < n;i++) cin >> y[i];

    sort(y, y+n);

    memset(memo, -1, sizeof(memo));

    cout << dp(0, 0) << endl;
    return 0;
}
0