結果

問題 No.2215 Slide Subset Sum
ユーザー SSRSSSRS
提出日時 2023-02-10 22:08:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,720 bytes
コンパイル時間 4,159 ms
コンパイル使用メモリ 221,004 KB
実行使用メモリ 172,672 KB
最終ジャッジ日時 2023-09-21 23:24:39
合計ジャッジ時間 12,818 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 647 ms
31,908 KB
testcase_01 AC 2,545 ms
168,228 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/convolution>
using namespace std;
const long long MOD = 998244353;
template <typename T>
struct sliding_window_aggregation{
  function<T(T, T)> f;
  T E;
  stack<pair<T, T>> fr, bk;
  sliding_window_aggregation(function<T(T, T)> f, T E): f(f), E(E){
  }
  void push(T x){
    if (fr.empty()){
      fr.push(make_pair(x, x));
    } else {
      fr.push(make_pair(x, f(fr.top().second, x)));
    }
  }
  void pop(){
    if (bk.empty()){
      while (!fr.empty()){
        T x = fr.top().first;
        fr.pop();
        if (bk.empty()){
          bk.push(make_pair(x, x));
        } else {
          bk.push(make_pair(x, f(x, bk.top().second)));
        }
      }
    }
    bk.pop();
  }
  T get(){
    T ans1 = E;
    if (!fr.empty()){
      ans1 = fr.top().second;
    }
    T ans2 = E;
    if (!bk.empty()){
      ans2 = bk.top().second;
    }
    return f(ans2, ans1);
  }
};
int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<vector<long long>> B(N, vector<long long>(K, 0));
  for (int i = 0; i < N; i++){
    B[i][0]++;
    B[i][A[i]]++;
  }
  auto op = [&](vector<long long> A, vector<long long> B){
    vector<long long> C = atcoder::convolution(A, B);
    for (int i = K; i < K * 2 - 1; i++){
      C[i - K] += C[i];
      C[i - K] %= MOD;
    }
    C.resize(K);
    return C;
  };
  vector<long long> E(K, 0);
  E[0] = 1;
  sliding_window_aggregation<vector<long long>> S(op, E);
  for (int i = 0; i < M; i++){
    S.push(B[i]);
  }
  for (int i = 0; i <= N - M; i++){
    cout << (S.get()[0] + MOD - 1) % MOD << endl;
    if (i < N - M){
      S.pop();
      S.push(B[i + M]);
    }
  }
}
0