結果

問題 No.2378 Cards and Subsequences
ユーザー tomo0608tomo0608
提出日時 2023-07-07 23:22:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 11,870 bytes
コンパイル時間 2,657 ms
コンパイル使用メモリ 224,288 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-07-21 19:47:12
合計ジャッジ時間 4,659 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 28 ms
19,072 KB
testcase_15 AC 26 ms
19,072 KB
testcase_16 AC 26 ms
19,072 KB
testcase_17 AC 26 ms
19,072 KB
testcase_18 AC 27 ms
19,072 KB
testcase_19 AC 26 ms
19,072 KB
testcase_20 AC 26 ms
18,944 KB
testcase_21 AC 27 ms
19,072 KB
testcase_22 AC 25 ms
19,072 KB
testcase_23 AC 25 ms
19,072 KB
testcase_24 AC 24 ms
19,072 KB
testcase_25 AC 24 ms
18,944 KB
testcase_26 AC 23 ms
19,072 KB
testcase_27 AC 23 ms
19,072 KB
testcase_28 AC 24 ms
19,072 KB
testcase_29 AC 30 ms
19,072 KB
testcase_30 AC 31 ms
19,072 KB
testcase_31 AC 32 ms
19,072 KB
testcase_32 AC 31 ms
19,072 KB
testcase_33 AC 31 ms
19,072 KB
testcase_34 AC 30 ms
19,072 KB
testcase_35 AC 21 ms
19,072 KB
testcase_36 AC 26 ms
19,072 KB
testcase_37 AC 27 ms
19,072 KB
testcase_38 AC 26 ms
18,944 KB
testcase_39 AC 26 ms
19,072 KB
testcase_40 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region competitive_programming
#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

//#include<atcoder/dsu>
//#include "Rollback_dsu.hpp"
//#include "Partial_Persistent_DSU.hpp"

//#include<atcoder/math>

#include<atcoder/modint>

namespace tomo0608 {
    std::istream& operator>>(std::istream& is, atcoder::modint998244353& a) { long long v; is >> v; a = v; return is; }
    std::ostream& operator<<(std::ostream& os, const atcoder::modint998244353& a) { return os << a.val(); }
    std::istream& operator>>(std::istream& is, atcoder::modint1000000007& a) { long long v; is >> v; a = v; return is; }
    std::ostream& operator<<(std::ostream& os, const atcoder::modint1000000007& a) { return os << a.val(); }
    template<int m> std::istream& operator>>(std::istream& is, atcoder::static_modint<m>& a) { long long v; is >> v; a = v; return is; }
    template<int m> std::ostream& operator<<(std::ostream& os, const atcoder::static_modint<m>& a) { return os << a.val(); }
    template<int m> std::istream& operator>>(std::istream& is, atcoder::dynamic_modint<m>& a) { long long v; is >> v; a = v; return is; }
    template<int m> std::ostream& operator<<(std::ostream& os, const atcoder::dynamic_modint<m>& a) { return os << a.val(); }

    // Binomial Coefficient of modint
    template<class mint> struct BiCoef {
        std::vector<mint> fact_, inv_, finv_;
        constexpr BiCoef() {}
        constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
            init(n);
        }
        constexpr void init(int n) noexcept {
            fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
            int MOD = fact_[0].mod();
            for (int i = 2; i < n; i++) {
                fact_[i] = fact_[i - 1] * i;
                inv_[i] = -inv_[MOD % i] * (MOD / i);
                finv_[i] = finv_[i - 1] * inv_[i];
            }
        }
        constexpr mint com(int n, int k) const noexcept {
            if (n < k || n < 0 || k < 0)return 0;
            return fact_[n] * finv_[k] * finv_[n - k];
        }
        constexpr mint perm(int n, int k) const noexcept {
            if (n < k || n < 0 || k < 0)return 0;
            return fact_[n] * finv_[n - k];
        }
        constexpr mint homo(int n, int r) { // The number of cases where k indistinguishable balls are put into n distinct boxes
            if (n < 0 || r < 0)return 0;
            return r == 0 ? 1 : com(n + r - 1, r);
        }
        constexpr mint second_stirling_number(int n, int r) { // The number of cases where n distinct balls are put into k indistinguishable boxes, with at least one ball in each box
            mint ret = 0;
            for (int i = 0; i <= r; i++) {
                mint tmp = com(r, i) * mint(i).pow(n);
                ret += ((r - i) & 1) ? -tmp : tmp;
            }
            return ret * finv_[r];
        }
        constexpr mint bell_number(int n, int r) { // The number of cases where n distinct balls are put into k indistinguishable boxes
            if (n == 0) return 1;
            r = std::min(r, n);
            std::vector<mint> pref(r + 1);
            pref[0] = 1;
            for (int i = 1; i <= r; i++) {
                if (i & 1) {
                    pref[i] = pref[i - 1] - finv_[i];
                }
                else {
                    pref[i] = pref[i - 1] + finv_[i];
                }
            }
            mint ret = 0;
            for (int i = 1; i <= r; i++) ret += mint(i).pow(n) * fact_[i] * pref[r - i];
            return ret;
        }

        constexpr mint fact(int n) const noexcept {
            if (n < 0)return 0;
            return fact_[n];
        }
        constexpr mint inv(int n) const noexcept {
            if (n < 0)return 0;
            return inv_[n];
        }
        constexpr mint finv(int n) const noexcept {
            if (n < 0)return 0;
            return finv_[n];
        }
        inline mint operator()(int n, int k) { return com(n, k); }

        constexpr mint com_naive(int n, int k) {
            if (n < k || n < 0 || k < 0)return 0;
            mint res = 1;
            k = std::min(k, n - k);
            for (int i = 1; i <= k; i++)res *= inv(i) * (n--);
            return res;
        }
    };
} // namespace tomo0608
//typedef atcoder::modint1000000007 mint;
typedef atcoder::modint998244353 mint;
//#include "Matrix.hpp"

//#include<atcoder/convolution>
//#include "Formal_Power_Series.hpp"
//#include "Bit_Convolution.hpp"

//#include<atcoder/maxflow>
//#include<atcoder/mincostflow>
//#include "Primal_Dual.hpp"
//#include "maxflow_mincap.hpp"

//#include<atcoder/fenwicktree>
//#include<atcoder/segtree>
//#include<atcoder/lazysegtree>
//#include "2D_Segment_Tree.hpp"
//#include "DisjointSparseTable.hpp"
//#include "SWAG.hpp"
//#include "Mo_algorithm.hpp"

//#include "Heavy_Light_Decomposition.hpp"
//#include "Binary_Trie.hpp"
//#include "LCT.hpp"
//#include "Slope_Trick.hpp"
//#include<atcoder/string>
//#include<atcoder/scc>



namespace tomo0608 {
    typedef long long ll;
    typedef long double ld;
    template <class T> using V = std::vector<T>;
    template <class T> using VV = V<V<T>>;
    template <class T> using VVV = V<VV<T>>;
    typedef std::pair<int, int> pii;
    typedef std::pair<long long, long long> pll;
    template<class... T>void input(T&... a) { (std::cin >> ... >> a); };

#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...) long long __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; IN(__VA_ARGS__)
#define VEC(type, name, size) std::vector<type> name(size);IN(name)
#define VECVEC(type, name, h, w) std::vector<std::vector<type>> name(h, std::vector<type>(w));IN(name)
    template<class T1, class T2> std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) { is >> p.first >> p.second; return is; }
    template<class T1, class T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
    template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) { for (auto& e : v) is >> e; return is; }
    template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { for (auto& e : v) os << e << ' '; return os; }
    template<typename T> std::ostream& operator << (std::ostream& os, std::set<T>& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr;++itr;if (itr != set_var.end()) os << ", ";itr--; }os << "}";return os; }
    template <typename T, typename U> std::ostream& operator<<(std::ostream& os, std::map<T, U>& map_var) { os << "{";for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--; }os << "}";return os; }

    void IN() {}
    template <class Head, class... Tail> void IN(Head& head, Tail &...tail) {
        std::cin >> head;
        IN(tail...);
    }
    void print() { std::cout << '\n'; }
    template<class T, class... Ts>void print(const T& a, const Ts&... b) { std::cout << a; (std::cout << ... << (std::cout << ' ', b)); std::cout << '\n'; }
    void drop() { std::cout << '\n';exit(0); }
    template<class T, class... Ts>void drop(const T& a, const Ts&... b) { std::cout << a; (std::cout << ... << (std::cout << ' ', b)); std::cout << '\n';exit(0); }
#ifdef __LOCAL
    void debug_out() { std::cerr << std::endl; }
    template < class Head, class... Tail> void debug_out(Head H, Tail... T) { std::cerr << ' ' << H; debug_out(T...); }
#define debug(...) std::cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) std::cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << std::endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif


#define rep1(a)          for(long long i = 0; i < a; i++)
#define rep2(i, a)       for(long long i = 0; i < a; i++)
#define rep3(i, a, b)    for(long long i = a; i < b; i++)
#define rep4(i, a, b, c) for(long long i = a; i < b; i += c)
#define drep1(a)          for(long long i = a-1; i >= 0; i--)
#define drep2(i, a)       for(long long i = a-1; i >= 0; i--)
#define drep3(i, a, b)    for(long long i = a-1; i >= b; i--)
#define drep4(i, a, b, c) for(long long i = a-1; i >= b; i -= c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define drep(...) overload4(__VA_ARGS__, drep4, drep3, drep2, drep1)(__VA_ARGS__)
#define endl '\n'
} // namespace tomo0608

namespace tomo0608 {
#define ALL(x) x.begin(),x.end()
    template <class T = long long, class S> T SUM(const S& v) { return accumulate(ALL(v), T(0)); }
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define RSORT(v) sort(ALL(v)); reverse(ALL(v))
#define UNIQUE(x) SORT(x), x.erase(unique(ALL(x)), x.end())
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
    template <typename T> void zip(std::vector<T>& x) { std::vector<T> y = x;UNIQUE(y);for (int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); } }
    template<class T> using priority_queue_rev = std::priority_queue<T, std::vector<T>, std::greater<T>>;
    template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return 1; } return 0; }
    template<class T> inline int count_between(std::vector<T>& a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define bittest(n, k) ((n >> k) & 1)
    int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
    int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
    int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
    int lowbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); }
#define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(ALL(v)));)
    template <typename T, typename S> T ceil(T x, S y) {
        assert(y);
        return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y));
    }

    template <typename T, typename S> T floor(T x, S y) {
        assert(y);
        return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1)));
    }
}
//using namespace atcoder;
using namespace std;
using namespace tomo0608;
int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[8] = { 0, 1, 0, -1, 1, -1, -1, 1 };



// インタラクティブ問題のときは出力するたびにcout.flush();を忘れない!!!!!

void solve();
int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while (codeforces--) {
        solve();
    }
    return 0;
}
#pragma endregion

void solve() {
    LL(n, m, k);
    VEC(ll, s, n);
    VEC(ll, a, m);
    VEC(ll, b, m);

    V<int> pre(n, 0);
    V<ll> tmp(m, 0);
    rep(i, n) {
        pre[i] = tmp[--s[i]];
        tmp[s[i]] = i + 1;
    }
    vector dp(n + 1, V<mint>(k + 1, 0));
    dp[0][0] = 1;
    mint ans = 0;
    rep(i, n) {
        rep(l, k + 1) {
            if (l - a[s[i]] >= 0) {
                dp[i + 1][l] += dp[i][l - a[s[i]]];
                if (pre[i] >= 1)dp[i + 1][l] -= dp[pre[i] - 1][l - a[s[i]]];
            }
            if (l - b[s[i]] >= 0) {
                dp[i + 1][l] += dp[i][l - b[s[i]]];
                if (pre[i] >= 1)dp[i + 1][l] -= dp[pre[i] - 1][l - b[s[i]]];
            }
        }
        ans += dp[i + 1][k];
        rep(l, k + 1)dp[i + 1][l] += dp[i][l];
    }
    print(ans);
}
0