結果

問題 No.838 Noelちゃんと星々3
ユーザー Arumakan1727Arumakan1727
提出日時 2019-06-15 17:59:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 165,916 KB
実行使用メモリ 4,756 KB
最終ジャッジ日時 2023-08-12 07:04:05
合計ジャッジ時間 3,728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
4,648 KB
testcase_01 AC 49 ms
4,532 KB
testcase_02 AC 48 ms
4,720 KB
testcase_03 AC 48 ms
4,580 KB
testcase_04 AC 49 ms
4,756 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 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,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
// Custom Header <<<
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;
// >>>

signed main()
{
    int N;
    int a[100010];

    cin >> N;
    rep(i, 0, N) cin >> a[i];

    sort(a, a+N);

    i64 dp[100010];
    dp[0] = LINF;
    dp[1] = a[1] - a[0];
    if (2 < N) dp[2] = a[2] - a[0];

    for (int i = 3; i < N; ++i) {
        dp[i] = min(
                dp[i-2] + (a[i] - a[i-1]),
                dp[i-3] + (a[i] - a[i-2]));
    }

    cout << (dp[N-1]) << endl;

    return 0;
}

/* vim:set foldmethod=marker foldmarker=<<<,>>> : */
0