結果

問題 No.2378 Cards and Subsequences
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-06-30 08:23:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,110 bytes
コンパイル時間 3,466 ms
コンパイル使用メモリ 223,716 KB
実行使用メモリ 38,940 KB
最終ジャッジ日時 2023-09-28 21:41:50
合計ジャッジ時間 7,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 39 ms
5,900 KB
testcase_07 AC 56 ms
7,304 KB
testcase_08 AC 82 ms
7,964 KB
testcase_09 AC 144 ms
8,884 KB
testcase_10 AC 11 ms
4,976 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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