結果
| 問題 |
No.2429 Happiest Tabehodai Ways
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-18 21:57:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 3,075 ms |
| コンパイル使用メモリ | 249,844 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 07:58:57 |
| 合計ジャッジ時間 | 4,286 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 44 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k; cin >> n >> k;
vector<int> c(n), d(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
for (int i = 0; i < n; i++) {
cin >> d[i];
}
vector<pair<int, mint>> dp(k + 1, {-1, 0});
dp[0] = {0, 1};
for (int i = 1; i <= k; i++) {
for (int j = 0; j < n; j++) {
if (i >= c[j] && dp[i - c[j]].first != -1) {
auto [sd, cnt] = dp[i - c[j]];
sd += d[j];
if (sd > dp[i].first) {
dp[i] = {sd, cnt};
} else if (sd == dp[i].first) {
dp[i].second += cnt;
}
}
}
}
pair<int, mint> ans = {-1, 0};
for (int i = k; i >= 0; i--) {
if (dp[i].first > ans.first) {
ans = dp[i];
} else if (dp[i].first == ans.first) {
ans.second += dp[i].second;
}
}
cout << ans.first << '\n' << ans.second.val();
}