結果
問題 |
No.2701 A cans -> B cans
|
ユーザー |
![]() |
提出日時 | 2024-03-29 22:24:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,626 bytes |
コンパイル時間 | 762 ms |
コンパイル使用メモリ | 80,768 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 16:13:28 |
合計ジャッジ時間 | 12,889 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 6 |
other | WA * 73 |
ソースコード
#include <iostream> using namespace std; using ll = long long; int N, M; ll A[5050], B[5050], C[5050]; struct dat{ ll mx1, id1, mx2, id2; void apply(ll m, int i){ if(id1 == i){ mx1 = max(mx1, m); }else if(id2 == i){ mx2 = max(mx2, m); if(mx1 < mx2){ swap(mx1, mx2); swap(id1, id2); } }else if(mx1 < m){ mx1 = m, id1 = i; }else if(mx2 < m){ mx2 = m, id2 = i; } } }; dat dp[5050], ndp[5050]; template<typename A, int N, typename T> void Fill(A (&arr)[N], const T &val){ fill((T*)arr, (T*)(arr + N), val); } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for(int i = 0;i < N;i++)cin >> A[i] >> B[i] >> C[i]; Fill(dp, dat({0, -1, 0, -1})); Fill(ndp, dat({0, -1, 0, -1})); for(int i = 0;i < N;i++){ for(int j = 0;j <= M;j++){ { ndp[j].apply(dp[j].mx1, dp[j].id1); int nm = j + A[i] - (ndp[j].id1 == i) * B[i]; if(nm <= M){ ndp[nm].apply(ndp[j].mx1 + B[i] * C[i], i); } } { ndp[j].apply(dp[j].mx2, dp[j].id2); int nm = j + A[i] - (ndp[j].id2 == i) * B[i]; if(nm <= M){ ndp[nm].apply(ndp[j].mx2 + B[i] * C[i], i); } } } swap(dp, ndp); Fill(ndp, dat({0, -1, 0, -1})); } for(int i = 0;i <= M;i++){ cout << dp[i].mx1 << "\n"; } return 0; }