結果
問題 |
No.2429 Happiest Tabehodai Ways
|
ユーザー |
![]() |
提出日時 | 2023-08-18 23:12:17 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,448 bytes |
コンパイル時間 | 2,821 ms |
コンパイル使用メモリ | 249,924 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-29 02:31:00 |
合計ジャッジ時間 | 3,775 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 43 WA * 1 |
ソースコード
#include <bits/stdc++.h> namespace nono { constexpr long long mod = 998244353; void solve() { int n, k; std::cin >> n >> k; std::vector<int> c(n), d(n); for (int i = 0; i < n; i++) std::cin >> c[i]; for (int i = 0; i < n; i++) std::cin >> d[i]; const long long inf = 1e18; std::vector<long long> dp(k + 1, -inf); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= k; j++) { // use if (dp[j] != -inf and j + c[i] <= k) { dp[j + c[i]] = std::max(dp[j + c[i]], dp[j] + d[i]); } } } long long happy = *std::max_element(dp.begin(), dp.end()); int max_i = -1; for (int i = 0; i <= k; i++) { if (dp[i] == happy) { max_i = i; break; } } // std::cout << happy << std::endl; std::vector<long long> ans(max_i + 1); ans[0] = 1; for (int i = 0; i < max_i; i++) { for (int j = 0; j < n; j++) { if (i + c[j] <= max_i and dp[i] + d[j] == dp[i + c[j]]) { ans[i + c[j]] += ans[i]; ans[i + c[j]] %= mod; } } } std::cout << happy << std::endl; std::cout << ans[max_i] << std::endl; } } // namespace nono int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(15); int t = 1; // std::cin >> t; while (t--) nono::solve(); }