結果

問題 No.2215 Slide Subset Sum
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-02-10 22:58:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 3,000 ms
コード長 3,515 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 208,552 KB
実行使用メモリ 87,620 KB
最終ジャッジ日時 2023-09-22 00:08:00
合計ジャッジ時間 12,944 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
4,376 KB
testcase_01 AC 323 ms
4,380 KB
testcase_02 AC 324 ms
4,376 KB
testcase_03 AC 324 ms
4,376 KB
testcase_04 AC 329 ms
5,808 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 297 ms
42,912 KB
testcase_18 AC 289 ms
37,364 KB
testcase_19 AC 327 ms
5,200 KB
testcase_20 AC 254 ms
47,268 KB
testcase_21 AC 323 ms
13,712 KB
testcase_22 AC 256 ms
50,324 KB
testcase_23 AC 261 ms
81,324 KB
testcase_24 AC 264 ms
81,864 KB
testcase_25 AC 259 ms
74,084 KB
testcase_26 AC 256 ms
50,816 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 24 ms
15,648 KB
testcase_29 AC 22 ms
5,440 KB
testcase_30 AC 143 ms
4,380 KB
testcase_31 AC 95 ms
36,244 KB
testcase_32 AC 28 ms
4,568 KB
testcase_33 AC 202 ms
11,932 KB
testcase_34 AC 166 ms
37,204 KB
testcase_35 AC 33 ms
6,016 KB
testcase_36 AC 50 ms
16,596 KB
testcase_37 AC 167 ms
87,416 KB
testcase_38 AC 99 ms
87,620 KB
testcase_39 AC 322 ms
4,376 KB
testcase_40 AC 57 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 253 ms
46,952 KB
testcase_43 AC 338 ms
8,388 KB
testcase_44 AC 327 ms
8,328 KB
testcase_45 AC 262 ms
69,192 KB
testcase_46 AC 260 ms
70,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const long long MD = 998244353;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){
        if(d<0) d+=MOD;
    };
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
typedef array<mint,100> ss;
int k;
ss add(ss& a, int v) {
    ss b = a;
    for(int j=0;j<k;++j) {
        b[(j+v)%k]+=a[j];
    }
    return b;
}
struct sta {
    stack<ss> st;
    stack<int> s;
    sta() {
        ss cur = {};
        cur[0]=1;
        st.push(cur);
    }

    void add(int i) {
        s.push(i);
        st.push(::add(st.top(),i));
    }
    int pop() {
        st.pop();
        int tmp = s.top();
        s.pop();
        return tmp;
    }
    bool empty() {return s.empty();}
    ss& myss() {return st.top();}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin >> n >> m >> k;
    sta s1 = {},s2 = {};
    auto remove = [&]() {
        if(s1.empty()) {
            while(!s2.empty()) {
                s1.add(s2.pop());
            }
        }
        if(!s1.empty()) s1.pop();
    };
    vi a(n); for(int& i: a) cin >> i;
    for(int i=0;i<m;++i) {
        s2.add(a[i]);
    }
    
    for(int i=0;i+m<=n;++i) {
        mint ans=0;
        for(int i=0;i<k;++i) {
            ans+=s1.myss()[i]*s2.myss()[(k-i)%k];
        }
        cout << ans-1 << '\n';
        if(i+m!=n) {
            s2.add(a[i+m]);
            remove();
        }
    }
}
0