結果

問題 No.2215 Slide Subset Sum
ユーザー maksimmaksim
提出日時 2023-02-11 00:53:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,389 ms / 3,000 ms
コード長 1,534 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 168,644 KB
実行使用メモリ 58,940 KB
最終ジャッジ日時 2023-09-22 01:24:17
合計ジャッジ時間 20,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
6,652 KB
testcase_01 AC 1,389 ms
6,420 KB
testcase_02 AC 814 ms
6,572 KB
testcase_03 AC 821 ms
6,660 KB
testcase_04 AC 808 ms
7,612 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 558 ms
30,224 KB
testcase_18 AC 560 ms
26,780 KB
testcase_19 AC 810 ms
7,244 KB
testcase_20 AC 425 ms
32,580 KB
testcase_21 AC 745 ms
12,516 KB
testcase_22 AC 412 ms
34,652 KB
testcase_23 AC 301 ms
53,384 KB
testcase_24 AC 298 ms
53,504 KB
testcase_25 AC 330 ms
48,192 KB
testcase_26 AC 410 ms
34,880 KB
testcase_27 AC 27 ms
4,380 KB
testcase_28 AC 16 ms
10,900 KB
testcase_29 AC 45 ms
4,904 KB
testcase_30 AC 350 ms
5,120 KB
testcase_31 AC 92 ms
23,708 KB
testcase_32 AC 62 ms
4,504 KB
testcase_33 AC 442 ms
10,796 KB
testcase_34 AC 263 ms
25,932 KB
testcase_35 AC 52 ms
5,840 KB
testcase_36 AC 67 ms
11,708 KB
testcase_37 AC 265 ms
58,844 KB
testcase_38 AC 44 ms
58,940 KB
testcase_39 AC 1,388 ms
6,400 KB
testcase_40 AC 102 ms
6,656 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 550 ms
32,888 KB
testcase_43 AC 794 ms
9,176 KB
testcase_44 AC 796 ms
9,068 KB
testcase_45 AC 345 ms
45,580 KB
testcase_46 AC 346 ms
45,792 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int32_t main()’ 内:
main.cpp:58:18: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   58 |             auto [l,u]=v[pos];
      |                  ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int n,m,k;
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;
    }
}
int f(array<int,100> u,array<int,100> v)
{
    int ans=u[0]*v[0];ans%=p;
    for(int i=1;i<k;++i)
    {
        ans+=u[i]*v[k-i];ans%=p;
    }
    return ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m>>k;
    int a[n+1];for(int i=0;i<n;++i) {cin>>a[i];} a[n]=0;
    int ans[n]={0};
    for(int i=m;i<=n;i+=m)
    {
        array<int,100> u;
        for(int i=0;i<100;++i) u[i]=0;
        u[0]=1;
        vector<pair<int,array<int,100> > > v(m/3+1);
        int sz=0;
        for(int l=i;l>=max(0LL,i-m);l-=3)
        {
            v[sz++]={l,u};
            if(l>=1) add(u,a[l-1]); if(l>=2) add(u,a[l-2]);if(l>=3) add(u,a[l-3]);
        }
        array<int,100> d,d1;
        for(int i=0;i<100;++i) d1[i]=0;
        d1[0]=1;
        for(int r=i;r<=min(n,i+m);++r)
        {
            if(r!=i)
            {
                add(d1,a[r-1]);
            }
            d=d1;
            int pos=(i-r+m)/3;
            auto [l,u]=v[pos];
            while(l>r-m)
            {
                add(d,a[l-1]);
                --l;
            }
            ans[l]=f(d,u);
        }
    }
    for(int i=0;i<=n-m;++i)
    {
        cout<<(ans[i]+p-1)%p<<'\n';
    }
    return 0;
}
0