結果

問題 No.2378 Cards and Subsequences
ユーザー KowerKoint2010
提出日時 2023-06-30 08:23:58
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,110 bytes
コンパイル時間 11,008 ms
コンパイル使用メモリ 282,720 KB
最終ジャッジ日時 2025-02-15 03:18:15
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 9 TLE * 15 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#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<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];
    vector<vector<ll>> dp(k+1, vector<ll>(n+1)); // 総和がi、j-1終わり
    dp[0][0] = 1;
    vector<int> last_appeared(m, -1);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= k; j++) {
            for(int c : {a[s[i]], b[s[i]]}) {
                if(j+c <= k) {
                    for(int l = last_appeared[s[i]]+1; l <= i; l++) {
                        dp[j+c][i+1] += dp[j][l];
                    }
                    dp[j+c][i+1] %= MOD;
                }
            }
        }
        last_appeared[s[i]] = i;
    }
    ll ans = accumulate(dp[k].begin(), dp[k].end(), 0LL) % MOD;
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}
0