結果

問題 No.798 コレクション
ユーザー rtia_iidxrtia_iidx
提出日時 2019-03-15 22:21:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,336 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 109,256 KB
実行使用メモリ 24,184 KB
最終ジャッジ日時 2023-09-14 13:44:40
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 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 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 11 ms
12,360 KB
testcase_14 AC 17 ms
17,844 KB
testcase_15 AC 15 ms
15,780 KB
testcase_16 AC 8 ms
8,768 KB
testcase_17 AC 12 ms
12,480 KB
testcase_18 AC 23 ms
22,900 KB
testcase_19 AC 18 ms
18,552 KB
testcase_20 AC 8 ms
9,092 KB
testcase_21 AC 7 ms
8,328 KB
testcase_22 AC 15 ms
15,760 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 24 ms
24,184 KB
testcase_25 AC 24 ms
24,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    
    vector<ll> a(n),b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    vector<pair<ll,ll>> s;
    for(int i = 0; i < n; i++){
        s.push_back(make_pair(b[i],a[i]));
    }

    sort(s.begin(),s.end(),greater<pair<ll,ll>>());

    ll needs = (n/3)*2 + n%3;

    vector<vector<ll>> dp(n+1,vector<ll>(needs+1,INF));

    dp[0][0] = 0;

    for(int i = 1; i < n+1; i++){
        for(int j = 0; j <= needs; j++){
            dp[i][j] = dp[i-1][j];
        }

        for(int j = 1; j <= needs; j++){
            dp[i][j] = min(dp[i][j],dp[i-1][j-1] + s[i-1].first * (j-1) + s[i-1].second);
        }
    }

    cout << dp[n][needs] << endl;

    return 0;
}
0