結果

問題 No.2378 Cards and Subsequences
ユーザー 👑 hitonanodehitonanode
提出日時 2023-07-14 09:10:41
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,368 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 176,816 KB
実行使用メモリ 19,100 KB
最終ジャッジ日時 2023-10-13 21:57:00
合計ジャッジ時間 5,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 10 ms
8,744 KB
testcase_08 AC 10 ms
7,288 KB
testcase_09 AC 10 ms
6,384 KB
testcase_10 AC 8 ms
8,028 KB
testcase_11 AC 45 ms
18,892 KB
testcase_12 AC 45 ms
18,948 KB
testcase_13 AC 44 ms
18,964 KB
testcase_14 AC 44 ms
18,904 KB
testcase_15 AC 44 ms
18,804 KB
testcase_16 AC 45 ms
18,836 KB
testcase_17 AC 45 ms
19,100 KB
testcase_18 AC 45 ms
18,800 KB
testcase_19 AC 45 ms
18,896 KB
testcase_20 AC 45 ms
18,836 KB
testcase_21 AC 44 ms
18,792 KB
testcase_22 AC 44 ms
18,884 KB
testcase_23 AC 44 ms
18,836 KB
testcase_24 AC 44 ms
18,792 KB
testcase_25 AC 44 ms
18,836 KB
testcase_26 AC 54 ms
18,900 KB
testcase_27 AC 54 ms
19,036 KB
testcase_28 AC 54 ms
18,804 KB
testcase_29 AC 53 ms
18,792 KB
testcase_30 AC 54 ms
18,896 KB
testcase_31 AC 52 ms
18,892 KB
testcase_32 AC 34 ms
18,836 KB
testcase_33 AC 46 ms
18,964 KB
testcase_34 AC 45 ms
18,840 KB
testcase_35 AC 45 ms
18,904 KB
testcase_36 AC 45 ms
18,836 KB
testcase_37 AC 5 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }

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

int main() {
    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;

    vector<mint> dpall(K + 1), dpsnxt(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 = 0; k <= K; ++k) {
            if (k + a <= K) dpsnxt.at(k + a) += dpall.at(k) + dp.at(s).at(k);
            if (k + b <= K) dpsnxt.at(k + b) += dpall.at(k) + dp.at(s).at(k);
            dp.at(s).at(k) = -dpall.at(k);
            dpall.at(k) += dpsnxt.at(k);
            dpsnxt.at(k) = 0;
        }
    }
    cout << dpall.back().val() << '\n';
}
0