結果

問題 No.798 コレクション
ユーザー TiramisterTiramister
提出日時 2019-03-15 22:47:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 3,002 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 113,720 KB
実行使用メモリ 34,472 KB
最終ジャッジ日時 2023-09-14 13:59:32
合計ジャッジ時間 2,372 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 15 ms
16,652 KB
testcase_14 AC 23 ms
25,268 KB
testcase_15 AC 21 ms
21,936 KB
testcase_16 AC 11 ms
11,636 KB
testcase_17 AC 15 ms
17,256 KB
testcase_18 AC 30 ms
32,540 KB
testcase_19 AC 24 ms
26,480 KB
testcase_20 AC 11 ms
12,036 KB
testcase_21 AC 9 ms
10,876 KB
testcase_22 AC 20 ms
21,960 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 32 ms
34,472 KB
testcase_25 AC 32 ms
34,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// contancer library
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p);

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v) os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "{";
    for (auto vv : v) os << vv << ",";
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

template <class K, class T>
ostream& operator<<(ostream& os, map<K, T> v) {
    os << "{";
    for (auto vv : v) os << vv << ",";
    return os << "}";
}

template <class T>
ostream& operator<<(ostream& os, queue<T> q) {
    os << "[";
    while (!q.empty()) {
        os << q.front() << ",";
        q.pop();
    }
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, priority_queue<T> q) {
    os << "{";
    while (!q.empty()) {
        os << q.top() << ",";
        q.pop();
    }
    return os << "}";
}

const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
const ll INF = 1LL << 50;
// const ld PI = acos(-1);
// const ld EPS = 1e-10;
// mt19937 mt(ll(time(0)));

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...));
}

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <typename T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

template <typename T, typename U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

template <typename T, typename U>
T mpow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * b % MOD;
        n >>= 1;
        b = b * b % MOD;
    }
    return ret;
}


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, N + 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 <= N; ++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