結果

問題 No.2701 A cans -> B cans
ユーザー ripityripity
提出日時 2024-03-29 23:01:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 1,000 ms
コード長 941 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 208,688 KB
実行使用メモリ 198,912 KB
最終ジャッジ日時 2024-03-29 23:02:18
合計ジャッジ時間 14,794 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 8 ms
6,676 KB
testcase_04 AC 8 ms
6,676 KB
testcase_05 AC 8 ms
6,676 KB
testcase_06 AC 8 ms
6,676 KB
testcase_07 AC 8 ms
6,676 KB
testcase_08 AC 8 ms
6,676 KB
testcase_09 AC 8 ms
6,676 KB
testcase_10 AC 9 ms
6,676 KB
testcase_11 AC 8 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 8 ms
6,676 KB
testcase_14 AC 8 ms
6,676 KB
testcase_15 AC 8 ms
6,676 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 8 ms
6,676 KB
testcase_18 AC 8 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 8 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 247 ms
198,912 KB
testcase_24 AC 246 ms
198,912 KB
testcase_25 AC 241 ms
198,912 KB
testcase_26 AC 233 ms
198,912 KB
testcase_27 AC 232 ms
198,912 KB
testcase_28 AC 233 ms
198,912 KB
testcase_29 AC 233 ms
198,912 KB
testcase_30 AC 238 ms
198,912 KB
testcase_31 AC 233 ms
198,912 KB
testcase_32 AC 233 ms
198,912 KB
testcase_33 AC 236 ms
198,912 KB
testcase_34 AC 232 ms
198,912 KB
testcase_35 AC 233 ms
198,912 KB
testcase_36 AC 242 ms
198,912 KB
testcase_37 AC 235 ms
198,912 KB
testcase_38 AC 233 ms
198,912 KB
testcase_39 AC 232 ms
198,912 KB
testcase_40 AC 232 ms
198,912 KB
testcase_41 AC 239 ms
198,912 KB
testcase_42 AC 233 ms
198,912 KB
testcase_43 AC 233 ms
198,912 KB
testcase_44 AC 235 ms
198,912 KB
testcase_45 AC 235 ms
198,912 KB
testcase_46 AC 240 ms
198,912 KB
testcase_47 AC 232 ms
198,912 KB
testcase_48 AC 233 ms
198,912 KB
testcase_49 AC 235 ms
198,912 KB
testcase_50 AC 234 ms
198,912 KB
testcase_51 AC 239 ms
198,912 KB
testcase_52 AC 232 ms
198,912 KB
testcase_53 AC 233 ms
198,912 KB
testcase_54 AC 233 ms
198,912 KB
testcase_55 AC 233 ms
198,912 KB
testcase_56 AC 9 ms
6,676 KB
testcase_57 AC 9 ms
6,676 KB
testcase_58 AC 9 ms
6,676 KB
testcase_59 AC 9 ms
6,676 KB
testcase_60 AC 9 ms
6,676 KB
testcase_61 AC 8 ms
6,676 KB
testcase_62 AC 9 ms
6,676 KB
testcase_63 AC 9 ms
6,676 KB
testcase_64 AC 10 ms
6,676 KB
testcase_65 AC 10 ms
6,676 KB
testcase_66 AC 250 ms
198,912 KB
testcase_67 AC 247 ms
198,912 KB
testcase_68 AC 247 ms
198,912 KB
testcase_69 AC 250 ms
198,912 KB
testcase_70 AC 252 ms
198,912 KB
testcase_71 AC 248 ms
198,912 KB
testcase_72 AC 248 ms
198,912 KB
testcase_73 AC 247 ms
198,912 KB
testcase_74 AC 248 ms
198,912 KB
testcase_75 AC 254 ms
198,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  vector<long long> C(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i];
  }
  const long long INF = 1LL<<55;
  vector dp(N, vector<long long>(M+1, -INF));
  { // init
    dp[0][0] = 0;
    for(int k = 1; k*A[0]-(k-1)*B[0] <= M; k++) {
      dp[0][k*A[0]-(k-1)*B[0]] = k*B[0]*C[0];
    }
  }
  for(int i = 1; i < N; i++) {
    vector<long long> ep(M+1, -INF);
    for(int j = 0; j <= M; j++) {
      dp[i][j] = max(dp[i][j], dp[i-1][j]);
      dp[i][j] = max(dp[i][j], ep[j]);
      if(j+A[i] <= M) ep[j+A[i]] = max(ep[j+A[i]], dp[i-1][j]+B[i]*C[i]);
      if(j+A[i]-B[i] <= M) ep[j+A[i]-B[i]] = max(ep[j+A[i]-B[i]], ep[j]+B[i]*C[i]);
    }
  }
  long long ans = 0;
  for(int j = 1; j <= M; j++) {
    ans = max(ans, dp[N-1][j]);
    cout << ans << endl;
  }
}

/*

-0 : +0
(k-1)*B[i]-k*A[i] : k*B[i]*C[i]

*/
0