結果

問題 No.798 コレクション
ユーザー imulanimulan
提出日時 2019-03-17 17:15:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 173,128 KB
実行使用メモリ 34,956 KB
最終ジャッジ日時 2023-09-21 10:41:38
合計ジャッジ時間 3,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
34,724 KB
testcase_01 AC 10 ms
34,724 KB
testcase_02 AC 9 ms
34,664 KB
testcase_03 AC 9 ms
34,664 KB
testcase_04 AC 10 ms
34,716 KB
testcase_05 AC 10 ms
34,732 KB
testcase_06 AC 9 ms
34,784 KB
testcase_07 AC 10 ms
34,724 KB
testcase_08 AC 10 ms
34,720 KB
testcase_09 AC 9 ms
34,780 KB
testcase_10 AC 9 ms
34,720 KB
testcase_11 AC 9 ms
34,672 KB
testcase_12 AC 9 ms
34,724 KB
testcase_13 AC 14 ms
34,740 KB
testcase_14 AC 17 ms
34,684 KB
testcase_15 AC 16 ms
34,656 KB
testcase_16 AC 14 ms
34,672 KB
testcase_17 AC 15 ms
34,772 KB
testcase_18 AC 18 ms
34,872 KB
testcase_19 AC 17 ms
34,852 KB
testcase_20 AC 14 ms
34,920 KB
testcase_21 AC 13 ms
34,864 KB
testcase_22 AC 16 ms
34,684 KB
testcase_23 AC 9 ms
34,956 KB
testcase_24 AC 17 ms
34,672 KB
testcase_25 AC 19 ms
34,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const ll INF = LLONG_MAX/3;
const int N = 2002;
ll dp[N][N];

int main(){
    int n;
    cin >>n;

    vector<pi> v(n);
    rep(i,n){
        int a,b;
        cin >>a >>b;
        v[i] = {b,a};
    }
    sort(all(v));
    reverse(all(v));

    rep(i,N)rep(j,N) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n){
        int a = v[i].se, b = v[i].fi;
        // j番目に買う
        rep(j,N)if(dp[i][j] < INF){
            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+b*j));
        }
    }

    ll ans = INF;
    for(int i=1; i<=n; ++i){
        int num = 0;
        for(int j=1; j<=i; ++j){
            ++num;
            if(j%2 == 0) ++num;
        }
        if(num >= n) ans = min(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}
0