結果

問題 No.2378 Cards and Subsequences
ユーザー hitonanode
提出日時 2023-07-14 09:14:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 96,824 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-09-15 17:43:14
合計ジャッジ時間 3,351 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

#include <atcoder/modint>
using mint = atcoder::modint998244353;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> S(N), A(M), B(M);
    for (auto &x : S) cin >> x, --x;
    for (auto &x : A) cin >> x;
    for (auto &x : B) cin >> x;
    for (int i = 0; i < M; ++i) {
        if (A.at(i) > B.at(i)) std::swap(A.at(i), B.at(i));
    }

    vector<mint> dpall(K + 1);
    dpall.at(0) = 1;
    vector dp(M, vector<mint>(K + 1));

    for (const int s : S) {
        const int a = A.at(s), b = B.at(s);

        for (int k = K - a; k >= 0; --k) {
            dpall.at(k + a) += dpall.at(k) + dp.at(s).at(k);
            if (k + b <= K) dpall.at(k + b) += dpall.at(k) + dp.at(s).at(k);
            dp.at(s).at(k) = -dpall.at(k);
        }
    }
    cout << dpall.back().val() << '\n';
}
0