結果

問題 No.2378 Cards and Subsequences
ユーザー MagentorMagentor
提出日時 2023-06-26 22:11:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 919 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 209,712 KB
実行使用メモリ 50,536 KB
最終ジャッジ日時 2023-09-28 21:40:11
合計ジャッジ時間 5,736 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 6 ms
6,100 KB
testcase_07 AC 8 ms
7,956 KB
testcase_08 AC 10 ms
9,336 KB
testcase_09 AC 14 ms
12,712 KB
testcase_10 AC 4 ms
5,052 KB
testcase_11 AC 65 ms
50,008 KB
testcase_12 AC 65 ms
49,936 KB
testcase_13 AC 65 ms
50,028 KB
testcase_14 AC 64 ms
50,096 KB
testcase_15 AC 65 ms
50,112 KB
testcase_16 AC 64 ms
49,992 KB
testcase_17 AC 65 ms
50,040 KB
testcase_18 AC 66 ms
50,124 KB
testcase_19 AC 65 ms
50,108 KB
testcase_20 AC 65 ms
49,980 KB
testcase_21 AC 65 ms
49,976 KB
testcase_22 AC 64 ms
50,536 KB
testcase_23 AC 64 ms
49,936 KB
testcase_24 AC 65 ms
50,016 KB
testcase_25 AC 65 ms
50,104 KB
testcase_26 AC 85 ms
49,940 KB
testcase_27 AC 84 ms
49,972 KB
testcase_28 AC 84 ms
49,992 KB
testcase_29 AC 88 ms
50,112 KB
testcase_30 AC 89 ms
50,020 KB
testcase_31 AC 76 ms
49,940 KB
testcase_32 AC 56 ms
50,528 KB
testcase_33 AC 67 ms
49,992 KB
testcase_34 AC 66 ms
49,980 KB
testcase_35 AC 67 ms
50,044 KB
testcase_36 AC 67 ms
49,940 KB
testcase_37 AC 35 ms
35,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint.hpp>

using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i, n) for (int i=0; i<n; i++)

int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> s(n), a(m), b(m);
    rep(i, n) {
        cin >> s[i];
        s[i]--;
    }
    rep(i, m) cin >> a[i];
    rep(i, m) cin >> b[i];
    vector br(n+1, vector<ll>(m, 0));
    for (int i = 1; i <= n; i++) {
        rep(j, m) br[i][j] = br[i-1][j];
        br[i][s[i-1]] = i;
    }
    vector dp(n+2, vector<mint>(k+1, 0));
    dp[1][0] = 1;
    for (int i=2; i < n+2; i++) rep(j, k+1) {
        ll si = s[i-2];
        ll bpos = br[i-2][si];
        if (j - a[si] >= 0) dp[i][j] += dp[i-1][j-a[si]] - dp[bpos][j-a[si]];
        if (j - b[si] >= 0) dp[i][j] += dp[i-1][j-b[si]] - dp[bpos][j-b[si]];
        dp[i][j] += dp[i-1][j];
    }
    cout << dp[n+1][k].val() << '\n';
}
0