結果

問題 No.2378 Cards and Subsequences
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-06-30 08:06:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 203,232 KB
実行使用メモリ 19,372 KB
最終ジャッジ日時 2023-09-28 21:40:28
合計ジャッジ時間 7,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 9 ms
5,368 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 108 ms
19,132 KB
testcase_22 AC 107 ms
19,064 KB
testcase_23 AC 108 ms
19,056 KB
testcase_24 AC 108 ms
19,080 KB
testcase_25 AC 108 ms
19,152 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 188 ms
19,084 KB
testcase_32 AC 80 ms
19,072 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    constexpr ll MOD = 998244353;
    int n, m, k; cin >> n >> m >> k;
    vector<vector<int>> dp(k+1, vector<int>(n+1)); // 総和がi、[0, j)を使う
    vector<int> s(n), a(m), b(m);
    for(int i = 0; i < n; i++) {
        cin >> s[i];
        s[i]--;
    }
    for(int i = 0; i < m; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    dp[0][0] = 1;
    vector<int> last_appeared(m, -1);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= k; j++) dp[j][i+1] = dp[j][i];
        for(int j = 0; j <= k; j++) {
            for(int c : {a[s[i]], b[s[i]]}) {
                if(j+c <= k) {
                    dp[j+c][i+1] += dp[j][i];
                    if(last_appeared[s[i]] != -1) {
                        dp[j+c][i+1] -= dp[j][last_appeared[s[i]]];
                    }
                    dp[j+c][i+1] %= MOD;
                }
            }
        }
        last_appeared[s[i]] = i;
    }
    int ans = dp[k][n];
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}
0