結果

問題 No.798 コレクション
ユーザー koi_kotyakoi_kotya
提出日時 2019-03-15 22:16:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 175,976 KB
実行使用メモリ 34,540 KB
最終ジャッジ日時 2023-09-14 13:42:54
合計ジャッジ時間 2,998 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 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,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 17 ms
16,716 KB
testcase_14 AC 27 ms
25,124 KB
testcase_15 AC 23 ms
22,288 KB
testcase_16 AC 11 ms
11,836 KB
testcase_17 AC 17 ms
17,296 KB
testcase_18 AC 34 ms
32,648 KB
testcase_19 AC 28 ms
26,488 KB
testcase_20 AC 11 ms
11,960 KB
testcase_21 AC 11 ms
10,916 KB
testcase_22 AC 23 ms
21,948 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 36 ms
34,540 KB
testcase_25 AC 36 ms
34,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    vector<P> s(n);
    for (int i = 0;i < n;++i) cin >> s[i].second >> s[i].first;
    sort(s.begin(),s.end(),greater<P>());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,1LL<<50));
    dp[0][0] = 0;
    for (int i = 0;i < n;++i) {
        dp[i+1] = dp[i];
        for (int j = 0;j < n;++j) dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+s[i].second+s[i].first*j);
    }
    int m = (n-1)/3*2+n%3;
    if (n%3 == 0) m += 2;
    cout << dp[n][m] << endl;
    return 0;
}
0