結果

問題 No.838 Noelちゃんと星々3
ユーザー kimiyukikimiyuki
提出日時 2019-06-14 22:13:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,346 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 203,700 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-26 16:58:22
合計ジャッジ時間 3,597 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 99 ms
11,008 KB
testcase_02 AC 103 ms
11,136 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 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 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using ll = long long;
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }

ll solve(int n, vector<ll> & a) {
    map<ll, int> f;
    for (ll a_i : a) {
        ++ f[a_i];
    }
    vector<ll> dp(f.size() + 1, LLONG_MAX / 10);
    dp[0] = 0;
    int i = 0;
    for (auto it = f.begin(); it != f.end(); ++ it, ++ i) {
        if (i >= 1) {
            chmin(dp[i + 1], dp[i - 1] + (it->first - prev(it)->first) * it->second);
            chmin(dp[i + 1], dp[i - 1] + (it->first - prev(it)->first) * prev(it)->second);
        }
        if (i >= 2) {
            chmin(dp[i + 1], dp[i - 2] + (it->first - prev(it)->first) * prev(it)->second + (it->first - prev(prev(it))->first) * prev(prev(it))->second);
            chmin(dp[i + 1], dp[i - 2] + (it->first - prev(it)->first) * it->second + (prev(it)->first - prev(prev(it))->first) * prev(prev(it))->second);
            chmin(dp[i + 1], dp[i - 2] + (it->first - prev(prev(it))->first) * it->second + (prev(it)->first - prev(prev(it))->first) * prev(it)->second);
        }
    }
    return dp[f.size()];

}

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    cout << solve(n, a) << endl;
    return 0;
}
0