結果

問題 No.798 コレクション
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-15 23:03:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 69,572 KB
実行使用メモリ 34,884 KB
最終ジャッジ日時 2023-09-14 14:05:42
合計ジャッジ時間 1,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 12 ms
25,780 KB
testcase_14 AC 16 ms
30,036 KB
testcase_15 AC 15 ms
28,108 KB
testcase_16 AC 9 ms
21,400 KB
testcase_17 AC 12 ms
25,944 KB
testcase_18 AC 20 ms
34,088 KB
testcase_19 AC 17 ms
32,028 KB
testcase_20 AC 10 ms
21,360 KB
testcase_21 AC 9 ms
19,208 KB
testcase_22 AC 15 ms
28,004 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 20 ms
34,824 KB
testcase_25 AC 21 ms
34,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
int N;
ll dp[2010][2010] = {};
ll A[2010],B[2010];
vector<P> v;
int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i] >> B[i];
        v.push_back({B[i],i});
    }
    v.push_back(P(1e18,1e18));
    sort(v.begin(),v.end(),greater<P>());
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j] = 1e18;
        }
    }
    for(int i=1;i<=N;i++){
        int id = v[i].second;
     //   cerr << B[id] << endl;
        for(int j=0;j<=N;j++){
            if(j==0) dp[i][j] = min(dp[i-1][j],A[id]);
            else dp[i][j] = min(min(dp[i][j],dp[i-1][j]),dp[i-1][j-1]+A[id]+j*B[id]);
        }
    }
    int day;
    day = N-N/3;
    /*for(int i=1;i<=N;i++){
        for(int j=0;j<=N;j++){
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }
*/    cout << dp[N][day-1] << endl;
}
0