結果

問題 No.798 コレクション
ユーザー NOSSNOSS
提出日時 2019-03-16 00:45:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 173,572 KB
実行使用メモリ 34,832 KB
最終ジャッジ日時 2023-09-14 14:54:45
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 10 ms
25,788 KB
testcase_14 AC 12 ms
30,140 KB
testcase_15 AC 11 ms
28,036 KB
testcase_16 AC 8 ms
21,552 KB
testcase_17 AC 10 ms
25,760 KB
testcase_18 AC 15 ms
34,300 KB
testcase_19 AC 13 ms
32,064 KB
testcase_20 AC 8 ms
21,380 KB
testcase_21 AC 8 ms
19,180 KB
testcase_22 AC 11 ms
27,908 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 15 ms
34,832 KB
testcase_25 AC 16 ms
34,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int n, m;
ll dp[2005][2005];
vector<P> v;

int main() {
    cin >> n;
    m = n/3;
    REP(i,n){
        ll a, b;
        cin >> a >> b;
        v.push_back({b,a});
    }
    SORT(v);
    reverse(ALL(v));
    REP(i,n+1) fill(dp[i], dp[i]+n+1, LLINF/3);
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        ll a = v[i].second, b = v[i].first;
        dp[i+1][0] = dp[i][0] + b*i + a;
        for(int j=1;j<=m;j++){
            dp[i+1][j] = min(dp[i][j] + b*(i-j) + a, dp[i][j-1]);
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}
0