結果
問題 | No.2215 Slide Subset Sum |
ユーザー |
|
提出日時 | 2023-02-11 06:07:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,256 bytes |
コンパイル時間 | 1,688 ms |
コンパイル使用メモリ | 176,212 KB |
実行使用メモリ | 167,776 KB |
最終ジャッジ日時 | 2024-07-07 22:11:20 |
合計ジャッジ時間 | 13,936 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | AC * 10 WA * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using Vl = std::vector<ll> ; ll const m = 998244353; std::stack<Vl> st1, st2; int N, M, K; void Push(int a) { Vl A(K); if (st2.empty()) { A[0] = 1; A[a] ++; } else { auto& B = st2.top(); for (int i = 0; i < K; i ++) { A[i] = B[i] + B[(i + K - a) % K]; A[i] %= m; } } st2.push(A); } void Pop() { if (!st1.empty()) { st1.pop(); } else { while (!st2.empty()) { auto v = st2.top(); st2.pop(); st1.push(v); } st1.pop(); } } void CA() { Vl A(K), B(K); if (st1.empty()) { A[0] = 1; } else { A = st1.top(); } if (st2.empty()) { B[0] = 1; } else { B = st2.top(); } ll ans = m - 1; for (int i = 0; i < K; i ++) { ans += (A[i] * B[(K - i) % K]) % m; ans %= m; } cout << ans << endl; } int main () { cin >> N >> M >> K; for (int i = 0; i < M - 1; i ++) { int a; cin >> a; Push(a); } for (int i = M - 1; i < N; i ++) { int a; cin >> a; Push(a); CA(); Pop(); } }