結果

問題 No.1947 質より種類数
ユーザー umimelumimel
提出日時 2022-05-20 23:04:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,534 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 171,020 KB
実行使用メモリ 394,404 KB
最終ジャッジ日時 2023-10-20 13:58:21
合計ジャッジ時間 12,153 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
394,328 KB
testcase_01 AC 127 ms
394,328 KB
testcase_02 AC 125 ms
394,328 KB
testcase_03 AC 127 ms
394,328 KB
testcase_04 AC 128 ms
394,332 KB
testcase_05 AC 162 ms
394,328 KB
testcase_06 AC 102 ms
394,332 KB
testcase_07 AC 101 ms
394,332 KB
testcase_08 AC 101 ms
394,332 KB
testcase_09 AC 106 ms
394,332 KB
testcase_10 WA -
testcase_11 AC 110 ms
394,332 KB
testcase_12 AC 107 ms
394,332 KB
testcase_13 AC 103 ms
394,332 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 102 ms
394,332 KB
testcase_25 AC 101 ms
394,332 KB
testcase_26 AC 100 ms
394,328 KB
testcase_27 AC 100 ms
394,332 KB
testcase_28 AC 103 ms
394,332 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 5000;
const ll MAX_V = 5000;

ll dp[MAX_N][MAX_V][2];

int main(){
    ll N, V, C;
    cin >> N >> V >> C;

    vector<ll> v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];

    memset(dp, -1, sizeof(dp));
    dp[0][0][0] = 0;
    dp[0][0][1] = 0;
    for(ll i=1; i<=N; i++){
        for(ll j=0; j<=V; j++){
            dp[i][j][0] = max(dp[i-1][j][0], dp[i-1][j][1]);
            if(0 <= j-v[i-1]){
                if(dp[i][j-v[i-1]][0] != -1){
                    dp[i][j][0] = max(dp[i][j][0], dp[i][j-v[i-1]][0]+w[i-1]);
                }
                if(dp[i][j-v[i-1]][1] != -1){
                    dp[i][j][0] = max(dp[i][j][0], dp[i][j-v[i-1]][1]+w[i-1]);
                }

                if(dp[i-1][j-v[i-1]][0] != -1){
                    dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-v[i-1]][0]+C+w[i-1]);
                }

                if(dp[i-1][j-v[i-1]][1] != -1){
                    dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-v[i-1]][1]+C+w[i-1]);
                }
            }
        }
    }

    ll ans = -INF;
    for(ll i=1; i<=N; i++) for(ll j=0; j<=V; j++) ans = max(ans, max(dp[i][j][0], dp[i][j][1]));
    cout << ans << endl;
}
0