結果

問題 No.798 コレクション
ユーザー TiramisterTiramister
提出日時 2019-03-15 23:57:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 81,324 KB
実行使用メモリ 23,888 KB
最終ジャッジ日時 2023-09-14 14:50:42
合計ジャッジ時間 2,101 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 10 ms
12,268 KB
testcase_14 AC 17 ms
17,756 KB
testcase_15 AC 14 ms
15,664 KB
testcase_16 AC 7 ms
8,916 KB
testcase_17 AC 11 ms
12,508 KB
testcase_18 AC 22 ms
22,488 KB
testcase_19 AC 17 ms
18,544 KB
testcase_20 AC 8 ms
9,004 KB
testcase_21 AC 7 ms
8,292 KB
testcase_22 AC 15 ms
15,704 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 22 ms
23,816 KB
testcase_25 AC 23 ms
23,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;

const ll INF = 1LL << 50;

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

int main() {
    int N;
    cin >> N;
    int day = N - N / 3;

    vector<pair<ll, ll>> A(N);
    for (auto& p : A) {
        cin >> p.second >> p.first;
    }
    sort(A.rbegin(), A.rend());

    auto dp = Vec<ll>(N + 1, day + 1, INF);
    dp[0][0] = 0;
    for (int i = 1; i <= N; ++i) {
        dp[i][0] = 0;
        auto p = A[i - 1];
        for (int d = 1; d <= day; ++d) {
            dp[i][d] = min(dp[i - 1][d], dp[i - 1][d - 1] + p.second + p.first * (d - 1));
        }
    }

    cout << dp[N][day] << endl;
    return 0;
}
0