結果
| 問題 | No.2215 Slide Subset Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-05 07:40:31 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 483 ms / 3,000 ms |
| コード長 | 2,833 bytes |
| 記録 | |
| コンパイル時間 | 4,378 ms |
| コンパイル使用メモリ | 386,868 KB |
| 実行使用メモリ | 369,536 KB |
| 最終ジャッジ日時 | 2026-05-05 07:40:49 |
| 合計ジャッジ時間 | 16,318 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
// using mint = modint1000000007;
template <typename T> using vec = vector<T>;
template <typename T> using pr = pair<T, T>;
template <typename T> using mipq = priority_queue<T, vec<T>, greater<T>>;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) for (auto i = decay_t<decltype(n)>{}; (i) < (n); ++(i))
#define rep2(i, l, r) for (auto i = (l); (i) < (r); ++(i))
#define rep3(i, l, r, d) for (auto i = (l); (i) < (r); i += (d))
#define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i, r, l) for (int i = (r); i >= (l); --i)
template <class T> bool chmax(T &a, const T b) { return (a < b ? a = b, true : false); }
template <class T> bool chmin(T &a, const T b) { return (a > b ? a = b, true : false); }
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T = 1;
// cin >> T;
while (T--) solve();
}
template <class S,
auto op>
struct SWAG {
vec<S> front, back, cumf, cumb;
SWAG() {}
void push_back(S x) {
if (front.empty()) return push_front(x);
back.emplace_back(x);
cumb.emplace_back((cumb.empty() ? x : op(cumb.back(), x)));
}
void push_front(S x) {
front.emplace_back(x);
cumf.emplace_back((cumf.empty() ? x : op(x, cumf.back())));
}
void init(vec<S> dat) {
int n = dat.size();
rrep(i, n - 1, 0) push_front(dat[i]);
}
void pop_front() {
assert(!front.empty());
front.pop_back();
cumf.pop_back();
if (front.empty()) {
vec<S> dat = back;
back.clear();
cumb.clear();
init(dat);
}
}
void fold() { return op(cumf.back(), cumb.back()); }
};
struct S {
int x;
vec<mint> val;
};
int K;
S op(S a, S b) {
if (a.x > b.x) swap(a, b);
assert(b.x != -1);
S res;
res.x = -1;
res.val = a.val;
rep(i, K) res.val[(i + b.x) % K] += a.val[i];
return res;
};
void solve() {
int N, M;
cin >> N >> M >> K;
SWAG<S, op> s;
auto get = [&] {
if (s.cumf.empty()) return s.cumb.back().val[0];
else if (s.cumb.empty()) return s.cumf.back().val[0];
mint res = 0;
rep(i, K) res += s.cumf.back().val[i] * s.cumb.back().val[(K - i) % K];
return res;
};
rep(i, N) {
int a;
cin >> a;
vec<mint> val(K);
val[0] = 1;
val[a] += 1;
s.push_back({a, val});
if (M - 1 <= i) {
cout << (get() - 1).val() << '\n';
s.pop_front();
}
}
}