結果

問題 No.2378 Cards and Subsequences
ユーザー ぷらぷら
提出日時 2023-07-07 21:56:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 260 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 3,038 ms
コンパイル使用メモリ 200,172 KB
実行使用メモリ 52,788 KB
最終ジャッジ日時 2023-09-28 23:06:38
合計ジャッジ時間 10,904 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,632 KB
testcase_01 AC 2 ms
5,420 KB
testcase_02 AC 2 ms
5,660 KB
testcase_03 AC 7 ms
8,704 KB
testcase_04 AC 8 ms
9,928 KB
testcase_05 AC 7 ms
9,060 KB
testcase_06 AC 16 ms
13,420 KB
testcase_07 AC 38 ms
20,744 KB
testcase_08 AC 39 ms
19,932 KB
testcase_09 AC 41 ms
19,948 KB
testcase_10 AC 23 ms
16,992 KB
testcase_11 AC 252 ms
51,936 KB
testcase_12 AC 249 ms
51,956 KB
testcase_13 AC 254 ms
52,016 KB
testcase_14 AC 258 ms
52,120 KB
testcase_15 AC 260 ms
51,976 KB
testcase_16 AC 255 ms
52,016 KB
testcase_17 AC 250 ms
52,008 KB
testcase_18 AC 256 ms
52,084 KB
testcase_19 AC 256 ms
52,020 KB
testcase_20 AC 260 ms
51,936 KB
testcase_21 AC 133 ms
51,968 KB
testcase_22 AC 136 ms
52,116 KB
testcase_23 AC 133 ms
51,904 KB
testcase_24 AC 132 ms
52,044 KB
testcase_25 AC 133 ms
52,172 KB
testcase_26 AC 248 ms
44,896 KB
testcase_27 AC 246 ms
44,924 KB
testcase_28 AC 245 ms
44,872 KB
testcase_29 AC 251 ms
45,352 KB
testcase_30 AC 243 ms
45,360 KB
testcase_31 AC 240 ms
45,032 KB
testcase_32 AC 246 ms
52,788 KB
testcase_33 AC 246 ms
50,632 KB
testcase_34 AC 249 ms
50,836 KB
testcase_35 AC 249 ms
50,672 KB
testcase_36 AC 255 ms
50,544 KB
testcase_37 AC 16 ms
15,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 998244353;

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int dp[2020][4020],dp2[4020][2020],nxt[4020][2020];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,K;
    cin >> N >> M >> K;
    vector<int>S(N);
    for(int i = 0; i < N; i++) {
        cin >> S[i];
        S[i]--;
    }
    vector<int>A(M),B(M);
    for(int i = 0; i < M; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < M; i++) {
        cin >> B[i];
    }
    vector<int>f(M+1);
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(!f[S[i]]) {
            dp[i][0] = 1;
            f[S[i]] = 1;
        }
        for(int j = K; j >= 0; j--) {
            if(j) mpl(dp[i+1][j],dp[i][j]);
            int now = (dp[i][j]+mod-dp2[j][S[i]])%mod;
            if(j) mpl(dp2[j][S[i]],now);
            mpl(dp[i+1][j+A[S[i]]],now);
            mpl(dp[i+1][j+B[S[i]]],now);
            if(j+A[S[i]] == K) mpl(ans,now);
            if(j+B[S[i]] == K) mpl(ans,now);
        }
    }
    cout << ans << "\n";
}
0