結果

問題 No.798 コレクション
ユーザー tottoripapertottoripaper
提出日時 2019-03-16 00:59:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 172,272 KB
実行使用メモリ 38,224 KB
最終ジャッジ日時 2023-09-14 14:55:58
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
37,924 KB
testcase_01 AC 12 ms
37,864 KB
testcase_02 AC 12 ms
37,804 KB
testcase_03 AC 12 ms
38,060 KB
testcase_04 AC 12 ms
37,752 KB
testcase_05 AC 12 ms
37,752 KB
testcase_06 AC 12 ms
37,748 KB
testcase_07 AC 13 ms
37,928 KB
testcase_08 AC 12 ms
37,832 KB
testcase_09 AC 12 ms
37,864 KB
testcase_10 AC 12 ms
37,804 KB
testcase_11 AC 12 ms
37,808 KB
testcase_12 AC 13 ms
37,752 KB
testcase_13 AC 18 ms
37,868 KB
testcase_14 AC 23 ms
38,084 KB
testcase_15 AC 20 ms
37,904 KB
testcase_16 AC 16 ms
37,964 KB
testcase_17 AC 20 ms
37,932 KB
testcase_18 AC 26 ms
38,008 KB
testcase_19 AC 24 ms
38,224 KB
testcase_20 AC 17 ms
37,952 KB
testcase_21 AC 16 ms
37,920 KB
testcase_22 AC 21 ms
37,980 KB
testcase_23 AC 12 ms
37,752 KB
testcase_24 AC 26 ms
37,988 KB
testcase_25 AC 26 ms
37,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<ll,ll>;

int N, M;
P ps[2100];
ll dp[2100][2100];

ll rec(int i, int n, int m){
    if(i == N){
        return 0;
    }

    if(dp[i][n] != -1){
        return dp[i][n];
    }

    ll mn = std::numeric_limits<ll>::max();
    ll B, A;
    std::tie(B, A) = ps[i];

    if(n < N - M){
        mn = A + B * n + rec(i + 1, n + 1, m);
    }

    if(m < M){
        mn = std::min(mn, rec(i + 1, n, m + 1));
    }

    return dp[i][n] = mn;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    M = N / 3;

    for(int i=0;i<N;++i){
        ll A, B;
        std::cin >> A >> B;

        ps[i] = std::make_tuple(B, A);
    }

    std::sort(ps, ps + N);
    std::reverse(ps, ps + N);

    memset(dp, -1, sizeof(dp));

    ll mn = rec(0, 0, 0);
    std::cout << mn << std::endl;
}
0