結果

問題 No.2215 Slide Subset Sum
ユーザー umimelumimel
提出日時 2023-02-24 15:16:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,071 ms / 3,000 ms
コード長 2,405 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 179,148 KB
実行使用メモリ 170,916 KB
最終ジャッジ日時 2023-10-10 00:19:20
合計ジャッジ時間 28,376 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 357 ms
6,256 KB
testcase_01 AC 277 ms
6,156 KB
testcase_02 AC 1,054 ms
6,272 KB
testcase_03 AC 1,037 ms
6,408 KB
testcase_04 AC 1,068 ms
9,496 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,356 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 4 ms
4,352 KB
testcase_17 AC 886 ms
80,340 KB
testcase_18 AC 874 ms
69,768 KB
testcase_19 AC 1,071 ms
8,388 KB
testcase_20 AC 744 ms
88,776 KB
testcase_21 AC 1,020 ms
24,752 KB
testcase_22 AC 737 ms
95,108 KB
testcase_23 AC 684 ms
153,548 KB
testcase_24 AC 685 ms
154,464 KB
testcase_25 AC 697 ms
137,684 KB
testcase_26 AC 740 ms
95,752 KB
testcase_27 AC 43 ms
4,348 KB
testcase_28 AC 32 ms
8,976 KB
testcase_29 AC 64 ms
6,800 KB
testcase_30 AC 491 ms
4,964 KB
testcase_31 AC 224 ms
57,636 KB
testcase_32 AC 84 ms
5,352 KB
testcase_33 AC 632 ms
17,096 KB
testcase_34 AC 445 ms
42,428 KB
testcase_35 AC 116 ms
5,044 KB
testcase_36 AC 137 ms
27,392 KB
testcase_37 AC 669 ms
170,916 KB
testcase_38 AC 57 ms
17,788 KB
testcase_39 AC 281 ms
6,272 KB
testcase_40 AC 272 ms
6,148 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 884 ms
88,512 KB
testcase_43 AC 1,053 ms
14,340 KB
testcase_44 AC 1,057 ms
14,344 KB
testcase_45 AC 700 ms
129,696 KB
testcase_46 AC 702 ms
129,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll mod = MOD2;
    ll n, m, k; cin >> n >> m >> k;
    vector<ll> a(n); rep(i, n) cin >> a[i];

    stack<pair<ll, vector<ll>>> f, b;
    //初期化
    for(ll i=0; i<m-1; i++){
        if(i==0){
            vector<ll> dp(k, 0);
            dp[a[i]]=1;
            b.push({i, dp});
        }else{
            vector<ll> dp(k, 0);
            dp[a[i]]=1;
            for(ll j=0; j<k; j++) dp[(a[i]+j)%k]=(dp[(a[i]+j)%k] + b.top().se[(a[i]+j)%k]+b.top().se[j])%mod;
            b.push({i, dp});
        }
    }

    vector<ll> ans(n-m+1);
    for(ll i=0; i<n-m+1; i++){
        //a[i+m-1]を追加
        if((ll)b.size()==0){
            vector<ll> dp(k, 0);
            dp[a[i+m-1]]=1;
            b.push({i+m-1, dp});
        }else{
            vector<ll> dp(k, 0);
            dp[a[i+m-1]]=1;
            for(ll j=0; j<k; j++) dp[(a[i+m-1]+j)%k]=(dp[(a[i+m-1]+j)%k]+b.top().se[(a[i+m-1]+j)%k]+b.top().se[j])%mod;
            b.push({i+m-1, dp});
        }

        //求解
        if((ll)f.size()==0){
            ans[i] = b.top().se[0];
        }else{
            ans[i] = (f.top().se[0]+b.top().se[0])%mod;
            for(ll j=0; j<k; j++) ans[i] = (ans[i] + (f.top().se[j] * b.top().se[(k-j)%k])%mod)%mod;
        }

        //a[i]を削除
        if((ll)f.size()==0){
            while(b.top().fi!=i){
                if((ll)f.size()==0){
                    vector<ll> dp(k, 0);
                    dp[a[b.top().fi]]=1;
                    f.push({b.top().fi, dp});
                }else{
                    vector<ll> dp(k, 0);
                    dp[a[b.top().fi]]=1;
                    for(ll j=0; j<k; j++) dp[(a[b.top().fi]+j)%k]=(dp[(a[b.top().fi]+j)%k]+f.top().se[(a[b.top().fi]+j)%k]+f.top().se[j])%mod;
                    f.push({b.top().fi, dp});
                }
                b.pop();
            }
            b.pop();
        }else{
            f.pop();
        }
    }

    rep(i, n-m+1) cout << ans[i] << endl;
}
0