結果

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

ソースコード

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];
                    }
                }
            }
        }
        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