結果

問題 No.2378 Cards and Subsequences
ユーザー momoyuumomoyuu
提出日時 2023-07-08 16:41:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,405 ms / 2,000 ms
コード長 3,621 bytes
コンパイル時間 1,267 ms
コンパイル使用メモリ 128,000 KB
実行使用メモリ 34,608 KB
最終ジャッジ日時 2023-09-29 18:06:42
合計ジャッジ時間 24,067 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 17 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 67 ms
6,352 KB
testcase_07 AC 61 ms
6,992 KB
testcase_08 AC 80 ms
7,584 KB
testcase_09 AC 103 ms
8,876 KB
testcase_10 AC 20 ms
4,612 KB
testcase_11 AC 698 ms
34,608 KB
testcase_12 AC 686 ms
34,400 KB
testcase_13 AC 695 ms
34,440 KB
testcase_14 AC 682 ms
34,508 KB
testcase_15 AC 681 ms
34,428 KB
testcase_16 AC 678 ms
34,408 KB
testcase_17 AC 694 ms
34,412 KB
testcase_18 AC 687 ms
34,400 KB
testcase_19 AC 691 ms
34,400 KB
testcase_20 AC 693 ms
34,604 KB
testcase_21 AC 575 ms
34,440 KB
testcase_22 AC 576 ms
34,428 KB
testcase_23 AC 591 ms
34,404 KB
testcase_24 AC 584 ms
34,404 KB
testcase_25 AC 567 ms
34,404 KB
testcase_26 AC 1,321 ms
34,444 KB
testcase_27 AC 1,366 ms
34,444 KB
testcase_28 AC 1,388 ms
34,608 KB
testcase_29 AC 1,405 ms
34,448 KB
testcase_30 AC 1,390 ms
34,424 KB
testcase_31 AC 1,284 ms
34,428 KB
testcase_32 AC 30 ms
34,400 KB
testcase_33 AC 685 ms
34,484 KB
testcase_34 AC 703 ms
34,408 KB
testcase_35 AC 661 ms
34,436 KB
testcase_36 AC 692 ms
34,516 KB
testcase_37 AC 49 ms
5,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cmath>
#include<iomanip>
using namespace std;
using ll = long long;




const ll mod = 998'244'353;
//const ll mod = 1'000'000'007;
//const ll mod = 67'280'421'310'721;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint& a){
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(const mint& a){
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator*=(const  mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(long long n) const {
        assert(0 <= n);
        mint a = *this, r = 1;
        while (n) {
            if (n & 1) r *= a;
            a *= a;
            n >>= 1;
        }
        return r;
    }
    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint& a){
        return (*this)*=a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    bool operator==(const mint& a) const {
        return x == a.x;
    }
    bool operator<(const mint& a) const{
        return x < a.x;
    }
};

template< typename T >
struct BIT2D{
    int H,W;
    vector<vector<T>> data;
    BIT2D(int h,int w):H(h),W(w),data(h+1,vector<T>(w+1,0)){}

    void add(int h,int w,T x){
        h++;w++;
        for(int i = h;i<=H;i+=i&(-i)){
            for(int j = w;j<=W;j+=j&(-j)){
                data[i][j] += x;
            }
        }
    }

    //sum of [l,r)
    T sum(int h1,int w1,int h2,int w2){
        return sum(h2,w2)-sum(h2,w1)-sum(h1,w2)+sum(h1,w1);
    }

    T sum(int h,int w){
        T now = 0;
        for(int i = h;i>0;i-=i&(-i)){
            for(int j = w;j>0;j-=j&(-j)){
                now += data[i][j];
            }
        }
        return now;
    }
};  
template< typename T >
struct BIT{
    int n;
    vector<T> data;
    BIT(int n):n(n),data(n+1,0){}

    void add(int i,T x){
        i++;
        while(i<=n){
            data[i] += x;
            i += i & (-i);
        }
    }

    //sum of [l,r)
    T sum(int l,int r){
        return sum(r-1)-sum(l-1);
    }

    T sum(int i){
        i++;
        T now = 0;
        while(i>0){
            now += data[i];
            i -= i & (-i);
        }
        return now;
    }
};



int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> s(n),a(m),b(m);
    for(int i = 0;i<n;i++){
        cin>>s[i];
        s[i]--;
    }
    for(int i = 0;i<m;i++) cin>>a[i];
    for(int i = 0;i<m;i++) cin>>b[i];
    BIT2D<mint> bit(n+1,k+1);
    bit.add(0,0,1);
    vector<int> last(m,0);
    for(int i = 0;i<n;i++){
        int ni = last[s[i]];
        int nj = i;
        last[s[i]] = i+1;
        for(int j = 0;j<=k;j++){
            int want = j - a[s[i]];
            if(want>=0){
                bit.add(i+1,j,bit.sum(ni,want,nj+1,want+1));
            }
            want = j - b[s[i]];
            if(want>=0){
                bit.add(i+1,j,bit.sum(ni,want,nj+1,want+1));
            }
        }
    }
    cout<<bit.sum(0,k,n+1,k+1)<<endl;
}

0