結果

問題 No.2701 A cans -> B cans
ユーザー sibasyunsibasyun
提出日時 2024-04-25 14:21:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 413 ms / 1,000 ms
コード長 1,690 bytes
コンパイル時間 2,570 ms
コンパイル使用メモリ 205,368 KB
実行使用メモリ 395,136 KB
最終ジャッジ日時 2024-04-25 14:22:09
合計ジャッジ時間 21,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 8 ms
6,944 KB
testcase_08 AC 8 ms
6,944 KB
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 9 ms
6,940 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 8 ms
6,940 KB
testcase_19 AC 8 ms
6,944 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 8 ms
6,940 KB
testcase_22 AC 9 ms
6,940 KB
testcase_23 AC 9 ms
6,940 KB
testcase_24 AC 9 ms
6,940 KB
testcase_25 AC 9 ms
6,944 KB
testcase_26 AC 379 ms
395,136 KB
testcase_27 AC 376 ms
395,008 KB
testcase_28 AC 371 ms
394,880 KB
testcase_29 AC 381 ms
395,008 KB
testcase_30 AC 382 ms
395,008 KB
testcase_31 AC 384 ms
394,880 KB
testcase_32 AC 386 ms
395,008 KB
testcase_33 AC 380 ms
394,880 KB
testcase_34 AC 379 ms
394,880 KB
testcase_35 AC 387 ms
394,880 KB
testcase_36 AC 382 ms
394,880 KB
testcase_37 AC 381 ms
395,008 KB
testcase_38 AC 385 ms
395,008 KB
testcase_39 AC 387 ms
394,880 KB
testcase_40 AC 379 ms
394,880 KB
testcase_41 AC 389 ms
394,880 KB
testcase_42 AC 380 ms
394,880 KB
testcase_43 AC 377 ms
395,008 KB
testcase_44 AC 385 ms
395,008 KB
testcase_45 AC 378 ms
395,008 KB
testcase_46 AC 375 ms
394,880 KB
testcase_47 AC 382 ms
395,008 KB
testcase_48 AC 377 ms
395,008 KB
testcase_49 AC 379 ms
394,880 KB
testcase_50 AC 379 ms
395,008 KB
testcase_51 AC 372 ms
394,880 KB
testcase_52 AC 384 ms
395,008 KB
testcase_53 AC 378 ms
394,880 KB
testcase_54 AC 379 ms
394,880 KB
testcase_55 AC 387 ms
394,880 KB
testcase_56 AC 375 ms
394,880 KB
testcase_57 AC 380 ms
395,008 KB
testcase_58 AC 381 ms
394,880 KB
testcase_59 AC 10 ms
6,940 KB
testcase_60 AC 9 ms
6,944 KB
testcase_61 AC 10 ms
6,940 KB
testcase_62 AC 10 ms
6,940 KB
testcase_63 AC 9 ms
6,940 KB
testcase_64 AC 9 ms
6,940 KB
testcase_65 AC 8 ms
6,944 KB
testcase_66 AC 10 ms
6,944 KB
testcase_67 AC 9 ms
6,940 KB
testcase_68 AC 11 ms
6,944 KB
testcase_69 AC 412 ms
395,008 KB
testcase_70 AC 407 ms
394,880 KB
testcase_71 AC 410 ms
394,880 KB
testcase_72 AC 402 ms
394,880 KB
testcase_73 AC 404 ms
394,880 KB
testcase_74 AC 401 ms
394,880 KB
testcase_75 AC 409 ms
394,880 KB
testcase_76 AC 403 ms
394,880 KB
testcase_77 AC 404 ms
395,008 KB
testcase_78 AC 413 ms
394,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// A cans -> B cans
#include <bits/stdc++.h>
// #include <atcoder/all>
#include <iostream>
#include <math.h>

using namespace std;
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long;
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, f, n) for (int i = (int) f; i < (int)(n); i++)
#define repd(i, n, l) for (int i = (int) n; i >= (int) l; i--)

const ll inf = ll(1e16+7);

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> C;
    ll a, b, c;
    rep(i, n){
        cin >> a >> b >> c;
        C.push_back({a, b, c});
    }
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(2, vector<ll>(m+1, -inf)));
    dp[0][0][0] = 0;
    rep(i, n){
        ll a = C[i][0];
        ll b = C[i][1];
        ll c = C[i][2];
        for (int j = 0; j <= m; j++){
            dp[i+1][0][j] = max(dp[i][1][j], dp[i][0][j]);
        }
        for (int j = 0; j <= m; j++){
            if (j + a - b <= m && dp[i+1][1][j] >= 0){
                dp[i+1][1][j + a - b] = max(dp[i+1][1][j + a - b], dp[i+1][1][j] + b * c);
            }
            if (j + a <= m && dp[i+1][0][j] >= 0){
                dp[i+1][1][j + a] = max(dp[i+1][1][j+a], dp[i+1][0][j] + b * c);
            }
        }
    }
    vector<ll> A(m+1, 0);
    for (int i = 1; i <= m; i++){
        ll ans = max(dp[n][0][i], dp[n][1][i]);
        ans = max(ans, A[i-1]);
        cout << ans << endl;
        A[i] = ans;    
    }
    return 0;
}
0