結果

問題 No.2215 Slide Subset Sum
ユーザー milanis48663220milanis48663220
提出日時 2023-02-12 12:29:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 713 ms / 3,000 ms
コード長 3,058 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 129,016 KB
実行使用メモリ 90,636 KB
最終ジャッジ日時 2023-09-23 04:39:56
合計ジャッジ時間 20,429 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 328 ms
18,040 KB
testcase_01 AC 702 ms
89,816 KB
testcase_02 AC 696 ms
89,740 KB
testcase_03 AC 700 ms
89,804 KB
testcase_04 AC 690 ms
89,756 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 523 ms
90,048 KB
testcase_18 AC 537 ms
89,984 KB
testcase_19 AC 698 ms
89,716 KB
testcase_20 AC 457 ms
90,052 KB
testcase_21 AC 654 ms
89,848 KB
testcase_22 AC 452 ms
90,344 KB
testcase_23 AC 354 ms
90,496 KB
testcase_24 AC 353 ms
90,636 KB
testcase_25 AC 380 ms
90,560 KB
testcase_26 AC 448 ms
90,336 KB
testcase_27 AC 32 ms
5,976 KB
testcase_28 AC 21 ms
6,416 KB
testcase_29 AC 42 ms
8,856 KB
testcase_30 AC 331 ms
40,268 KB
testcase_31 AC 116 ms
32,596 KB
testcase_32 AC 56 ms
10,308 KB
testcase_33 AC 436 ms
54,604 KB
testcase_34 AC 288 ms
44,440 KB
testcase_35 AC 100 ms
9,128 KB
testcase_36 AC 79 ms
19,992 KB
testcase_37 AC 216 ms
90,600 KB
testcase_38 AC 34 ms
15,664 KB
testcase_39 AC 713 ms
89,736 KB
testcase_40 AC 300 ms
14,872 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 456 ms
90,104 KB
testcase_43 AC 671 ms
89,828 KB
testcase_44 AC 674 ms
89,752 KB
testcase_45 AC 392 ms
90,428 KB
testcase_46 AC 392 ms
90,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <stack>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m, k; cin >> n >> m >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    stack<int> stack_left, stack_right;
    auto dp = vec2d(n, k, mint(0));
    vector<mint> e(k); e[0] = 1;
    auto right_top = [&](){
        if(stack_right.empty()) return &e;
        return &dp[stack_right.top()];
    };
    auto push_left = [&](int i){
        dp[i].assign(k, mint(0));
        auto &v = stack_left.empty() ? e : dp[stack_left.top()];
        for(int j = 0; j < k; j++){
            dp[i][j] += v[j];
            dp[i][(j+a[i])%k] += v[j];
        }
        stack_left.push(i);
    };
    auto push_right = [&](int i){
        dp[i].assign(k, mint(0));
        auto &v = stack_right.empty() ? e : dp[stack_right.top()];
        for(int j = 0; j < k; j++){
            dp[i][j] += v[j];
            dp[i][(j+a[i])%k] += v[j];
        }
        stack_right.push(i);
    };
    auto pop = [&](){
        if(stack_left.empty()){
            while(!stack_right.empty()){
                int i = stack_right.top(); stack_right.pop();
                push_left(i);
            }
        }
        stack_left.pop();
    };
    auto ans = [&](){
        auto &v = stack_left.empty() ? e : dp[stack_left.top()];
        auto &u = stack_right.empty() ? e : dp[stack_right.top()];
        mint ret = 0;
        for(int i = 0; i < k; i++){
            ret += v[i]*u[(k-i)%k];
        }
        return ret;
    };
    for(int i = 0; i < m; i++) push_right(i);
    for(int i = m; i < n; i++){
        cout << ans()-1 << endl;
        push_right(i);
        pop();
    }
    cout << ans()-1 << endl;
}
0