結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー Manuel1024Manuel1024
提出日時 2023-08-18 23:48:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 915 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 15,268 KB
最終ジャッジ日時 2023-09-03 03:05:21
合計ジャッジ時間 6,442 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 915 ms
15,200 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,388 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
5,512 KB
testcase_14 AC 4 ms
5,564 KB
testcase_15 AC 20 ms
14,092 KB
testcase_16 AC 3 ms
4,456 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 7 ms
7,004 KB
testcase_19 AC 9 ms
9,596 KB
testcase_20 AC 5 ms
6,356 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 248 ms
8,816 KB
testcase_30 AC 31 ms
5,808 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 243 ms
11,948 KB
testcase_34 AC 65 ms
6,092 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 536 ms
10,628 KB
testcase_37 AC 15 ms
15,260 KB
testcase_38 AC 12 ms
13,152 KB
testcase_39 AC 14 ms
15,268 KB
testcase_40 AC 20 ms
15,200 KB
testcase_41 AC 13 ms
14,480 KB
testcase_42 AC 780 ms
14,468 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll MOD = 998244353;

int main(){
    int n, k; cin >> n >> k;
    vector<int> c(n), d(n);
    for(auto &it: c) cin >> it;
    for(auto &it: d) cin >> it;

    vector<vector<int>> dp(k+10, vector<int>(k+10, -(1 << 30)));
    vector<vector<ll>> cnt(k+10, vector<ll>(k+10, 0));
    dp[0][0] = 0;
    cnt[0][0] = 1;

    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(cnt[i][j] == 0) continue;
            for(int l = 0; l < n; l++){
                if(k < j+c[l]) continue;
                if(dp[i+1][j+c[l]] < dp[i][j]+d[l]){
                    dp[i+1][j+c[l]] = dp[i][j]+d[l];
                    cnt[i+1][j+c[l]] = cnt[i][j];
                }else if(dp[i+1][j+c[l]] == dp[i][j]+d[l]){
                    cnt[i+1][j+c[l]] = (cnt[i+1][j+c[l]]+cnt[i][j])%MOD;
                }
            }
        }
    }

    int maxc = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            maxc = max(dp[i][j], maxc);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(dp[i][j] == maxc){
                ans = (ans+cnt[i][j])%MOD;
            }
        }
    }
    cout << maxc << endl;
    cout << ans << endl;
    return 0;
}
0