結果

問題 No.2215 Slide Subset Sum
ユーザー jianglyjiangly
提出日時 2023-02-10 21:58:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 488 ms / 3,000 ms
コード長 3,164 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 207,660 KB
実行使用メモリ 175,976 KB
最終ジャッジ日時 2023-09-21 23:12:31
合計ジャッジ時間 14,821 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
31,772 KB
testcase_01 AC 205 ms
175,716 KB
testcase_02 AC 485 ms
175,816 KB
testcase_03 AC 482 ms
175,676 KB
testcase_04 AC 488 ms
175,744 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 428 ms
175,716 KB
testcase_18 AC 437 ms
175,704 KB
testcase_19 AC 488 ms
175,680 KB
testcase_20 AC 422 ms
175,780 KB
testcase_21 AC 476 ms
175,676 KB
testcase_22 AC 417 ms
175,852 KB
testcase_23 AC 364 ms
175,672 KB
testcase_24 AC 364 ms
175,660 KB
testcase_25 AC 377 ms
175,648 KB
testcase_26 AC 413 ms
175,756 KB
testcase_27 AC 17 ms
8,752 KB
testcase_28 AC 17 ms
9,560 KB
testcase_29 AC 29 ms
14,680 KB
testcase_30 AC 214 ms
76,652 KB
testcase_31 AC 120 ms
61,368 KB
testcase_32 AC 39 ms
17,180 KB
testcase_33 AC 281 ms
105,312 KB
testcase_34 AC 205 ms
84,732 KB
testcase_35 AC 37 ms
15,300 KB
testcase_36 AC 73 ms
36,224 KB
testcase_37 AC 352 ms
175,656 KB
testcase_38 AC 48 ms
25,508 KB
testcase_39 AC 204 ms
175,652 KB
testcase_40 AC 57 ms
25,548 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 423 ms
175,652 KB
testcase_43 AC 484 ms
175,792 KB
testcase_44 AC 482 ms
175,656 KB
testcase_45 AC 385 ms
175,976 KB
testcase_46 AC 385 ms
175,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;
template<class T>
T power(T a, i64 b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

template<int P>
struct MInt {
    int x;
    MInt() : x{} {}
    MInt(i64 x) : x{norm(x % P)} {}
    
    int norm(int x) const {
        if (x < 0) {
            x += P;
        }
        if (x >= P) {
            x -= P;
        }
        return x;
    }
    int val() const {
        return x;
    }
    MInt operator-() const {
        MInt res;
        res.x = norm(P - x);
        return res;
    }
    MInt inv() const {
        assert(x != 0);
        return power(*this, P - 2);
    }
    MInt &operator*=(const MInt &rhs) {
        x = 1LL * x * rhs.x % P;
        return *this;
    }
    MInt &operator+=(const MInt &rhs) {
        x = norm(x + rhs.x);
        return *this;
    }
    MInt &operator-=(const MInt &rhs) {
        x = norm(x - rhs.x);
        return *this;
    }
    MInt &operator/=(const MInt &rhs) {
        return *this *= rhs.inv();
    }
    friend MInt operator*(const MInt &lhs, const MInt &rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend MInt operator+(const MInt &lhs, const MInt &rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend MInt operator-(const MInt &lhs, const MInt &rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend MInt operator/(const MInt &lhs, const MInt &rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend std::istream &operator>>(std::istream &is, MInt &a) {
        i64 v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const MInt &a) {
        return os << a.val();
    }
};

constexpr int P = 998244353;
using Z = MInt<P>;


int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m, k;
    std::cin >> n >> m >> k;
    
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    std::vector pre(n, std::vector<Z>(k)), suf(pre);
    for (int i = 0; i < n; i++) {
        if (i % m == 0) {
            pre[i][0] += 1;
            pre[i][a[i]] += 1;
        } else {
            pre[i] = pre[i - 1];
            for (int j = 0; j < k; j++) {
                pre[i][(j + a[i]) % k] += pre[i - 1][j];
            }
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (i == n - 1 || i % m == m - 1) {
            suf[i][0] += 1;
            suf[i][a[i]] += 1;
        } else {
            suf[i] = suf[i + 1];
            for (int j = 0; j < k; j++) {
                suf[i][(j + a[i]) % k] += suf[i + 1][j];
            }
        }
    }
    
    for (int i = 0; i <= n - m; i++) {
        Z ans = 0;
        if (i % m == 0) {
            ans = suf[i][0];
        } else {
            for (int j = 0; j < k; j++) {
                ans += suf[i][j] * pre[i + m - 1][(k - j) % k];
            }
        }
        ans -= 1;
        std::cout << ans << "\n";
    }
    
    return 0;
}
0