結果

問題 No.798 コレクション
ユーザー veqccveqcc
提出日時 2019-03-15 22:28:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 103,892 KB
実行使用メモリ 34,932 KB
最終ジャッジ日時 2023-09-14 13:46:22
合計ジャッジ時間 2,222 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 12 ms
25,956 KB
testcase_14 AC 15 ms
30,056 KB
testcase_15 AC 13 ms
27,836 KB
testcase_16 AC 9 ms
21,756 KB
testcase_17 AC 12 ms
26,052 KB
testcase_18 AC 17 ms
33,984 KB
testcase_19 AC 15 ms
32,048 KB
testcase_20 AC 10 ms
21,780 KB
testcase_21 AC 9 ms
19,756 KB
testcase_22 AC 14 ms
28,060 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 17 ms
34,932 KB
testcase_25 AC 18 ms
34,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

const ll INF = 1LL << 60;
ll dp[2005][2005];
// i番目まで見た時にj個買っている時の金額

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    int m = n / 3 * 2 + n % 3;

    P A[n];
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        A[i] = P(b, a);
    }

    sort(A, A+n, greater<P>());

    fill(dp[0], dp[n+1], INF);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + A[i].second + A[i].first * j);
        }
    }


    cout << dp[n][m] << "\n";
    return 0;
}
0