結果
| 問題 |
No.2429 Happiest Tabehodai Ways
|
| コンテスト | |
| ユーザー |
nono00
|
| 提出日時 | 2023-08-18 23:07:02 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,430 bytes |
| コンパイル時間 | 3,311 ms |
| コンパイル使用メモリ | 250,748 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-29 02:31:06 |
| 合計ジャッジ時間 | 4,560 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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(k + 1);
ans[max_i] = 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;
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();
}
nono00