結果

問題 No.2215 Slide Subset Sum
ユーザー maksimmaksim
提出日時 2023-02-10 23:18:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,247 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 191,188 KB
実行使用メモリ 9,708 KB
最終ジャッジ日時 2023-09-22 00:21:04
合計ジャッジ時間 8,623 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
9,608 KB
testcase_01 AC 255 ms
9,708 KB
testcase_02 RE -
testcase_03 TLE -
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 #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
const int maxn=2e5+5;
const int maxn1=100;
int sq=25;
int n,m,k;
int a[maxn];
vector<int> ord[maxn];
map<pair<int,int>,array<int,100> > u;
int cyc=1;
array<int,100> v;
void add(array<int,100>& u,int x)
{
    for(int i=0;i<k;++i)
    {
        v[(i+x)%k]=u[i];
    }
    for(int i=0;i<k;++i)
    {
        u[i]+=v[i];
        if(u[i]>=p) u[i]-=p;
    }
}
array<int,100> merg(array<int,100> u,array<int,100> v)
{
    __int128 res[100]={0};
    for(int i=0;i<100;++i) res[i]=0;
    for(int i=0;i<k;++i)
    {
        if(!v[i]) continue;
        for(int j=0;j<k;++j)
        {
            res[i+j]+=(v[i]*u[j]);
        }
    }
    array<int,100> res1;for(int i=0;i<100;++i) res1[i]=0;
    for(int i=0;i<k;++i) res1[i]=res[i]%p;
    return res1;
}
int f2(int l,int r)
{
    int o=1;
    while(((r-1)/o)!=(l/o)) o*=2;
    o/=2;
    int pos=o*(l/o+1);
    return pos;
}
array<int,100> f(int l,int r,int de)
{
    if(u.count({l,r})) return u[{l,r}];
    if(r-l<sq) return {};
    if(de==0)
    {
    int l1=((l+sq)/sq)*sq;int r1=((r-1)/sq)*sq;
    if(l1>r1)
    {
        l1=l;r1=l;
    }
    ++cyc;
    array<int,100> h;
    if(r1-l1>sq)
    {
        h=f(l1,r1,1);
    }
    else
    {
        for(int i=0;i<100;++i) h[i]=0;
        h[0]=1;
        for(int i=l1;i<r1;++i) add(h,a[i]);
    }
    for(int i=l;i<l1;++i)
    {
        add(h,a[i]);
    }
    for(int i=r1;i<r;++i)
    {
        add(h,a[i]);
    }
    return h;
    }
    else
    {
        int pos=f2(l,r);
        array<int,100> h;
    if(pos-l>sq)
    {
        h=f(l,pos,1);
    }
    else
    {
        for(int i=0;i<100;++i) h[i]=0;
        h[0]=1;
        for(int i=l;i<pos;++i) add(h,a[i]);
    }
    if(r-pos>sq)
    {
        h=merg(h,f(pos,r,1));
    }
    else
    {
        for(int i=pos;i<r;++i) add(h,a[i]);
    }
    u[{l,r}]=h;
    return h;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m>>k;
    for(int i=0;i<n;++i) cin>>a[i];
    sq=min(sq,m);
    for(int i=0;i<=n-m;++i)
    {
        //f(i,i+m,0);
        cout<<((f(i,i+m,0)[0]-1)%p+p)%p<<'\n';
    }
    return 0;
}
0