結果
問題 |
No.2429 Happiest Tabehodai Ways
|
ユーザー |
![]() |
提出日時 | 2023-08-18 23:00:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,364 bytes |
コンパイル時間 | 3,060 ms |
コンパイル使用メモリ | 250,788 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-29 02:30:56 |
合計ジャッジ時間 | 4,133 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 WA * 10 |
ソースコード
#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()); // std::cout << happy << std::endl; std::vector<long long> ans(k + 1); ans[k] = 1; for (int i = k; i >= 0; i--) { for (int j = 0; j < n; j++) { if (i + c[j] <= k and dp[i + c[j]] == dp[i] + d[j]) { ans[i] += ans[i + c[j]]; ans[i] %= mod; } } } std::cout << happy << std::endl; if (happy == 0) { std::cout << 1 << std::endl; } else { std::cout << ans[0] << 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(); }