結果

問題 No.1947 質より種類数
ユーザー milanis48663220milanis48663220
提出日時 2022-05-20 22:03:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 503 ms / 2,000 ms
コード長 1,910 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 119,796 KB
実行使用メモリ 394,344 KB
最終ジャッジ日時 2023-10-20 12:43:23
合計ジャッジ時間 7,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 4 ms
5,784 KB
testcase_05 AC 4 ms
4,920 KB
testcase_06 AC 4 ms
5,164 KB
testcase_07 AC 4 ms
5,316 KB
testcase_08 AC 4 ms
5,848 KB
testcase_09 AC 13 ms
12,196 KB
testcase_10 AC 10 ms
9,540 KB
testcase_11 AC 27 ms
23,292 KB
testcase_12 AC 19 ms
17,040 KB
testcase_13 AC 9 ms
8,368 KB
testcase_14 AC 145 ms
112,604 KB
testcase_15 AC 74 ms
58,768 KB
testcase_16 AC 208 ms
162,784 KB
testcase_17 AC 264 ms
210,376 KB
testcase_18 AC 477 ms
373,556 KB
testcase_19 AC 408 ms
326,432 KB
testcase_20 AC 304 ms
245,624 KB
testcase_21 AC 362 ms
289,468 KB
testcase_22 AC 22 ms
19,388 KB
testcase_23 AC 169 ms
131,140 KB
testcase_24 AC 6 ms
6,416 KB
testcase_25 AC 5 ms
5,712 KB
testcase_26 AC 4 ms
4,536 KB
testcase_27 AC 4 ms
5,084 KB
testcase_28 AC 5 ms
5,628 KB
testcase_29 AC 499 ms
394,340 KB
testcase_30 AC 500 ms
394,344 KB
testcase_31 AC 2 ms
4,372 KB
testcase_32 AC 2 ms
4,372 KB
testcase_33 AC 2 ms
4,372 KB
testcase_34 AC 463 ms
394,304 KB
testcase_35 AC 83 ms
4,372 KB
testcase_36 AC 503 ms
394,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

ll dp[10001][5001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, V, C; cin >> n >> V >> C;
    vector<int> v(n), w(n);
    for(int i = 0; i < n; i++) cin >> v[i] >> w[i];
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= V; j++){
            chmax(dp[i+1][j], dp[i][j]);
            if(j+v[i] <= V) chmax(dp[i+1][j+v[i]], dp[i][j]+w[i]+C);
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= V; j++){
            chmax(dp[i+n+1][j], dp[i+n][j]);
            if(j >= v[i]) chmax(dp[i+n+1][j], dp[i+n+1][j-v[i]]+w[i]);
        }
    }
    ll ans = 0;
    for(int j = 0; j <= V; j++) chmax(ans, dp[2*n][j]);
    cout << ans << endl;
}
0