提出 #46945971


ソースコード 拡げる

#include<bits/stdc++.h>
#define For(i,l,r) for(int i=(l);i<=(r);++i)
const int N=2010;
const int mod=924844033;
typedef long long ll;
using namespace std;
typedef vector<ll> poly;
template<typename T1,typename T2>
void Add(T1 &a,T2 b){a+=b;if(a>=mod)a-=mod;return;}
template<typename T1,typename T2>
void Sub(T1 &a,T2 b){a-=b;if(a<0)a+=mod;return;}
struct Chain{int len;poly f;}chain[N<<1];
bool vis[N][2];
ll binom[N][N],fac[N];
int n,k,tot;
poly operator * (const poly &a,const poly &b)
{
    int len_a=(a.size()-1),len_b=(b.size()-1);poly res;res.resize((len_a+len_b+1));
    For(i,0,len_a){For(j,0,len_b){ll delta=a[i];(delta*=b[j])%=mod;Add(res[i+j],delta);}}
    return res;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;tot=0;For(i,1,n){vis[i][0]=false;vis[i][1]=false;}
    binom[0][0]=1;For(i,1,n)binom[i][0]=1;For(j,1,n)binom[0][j]=0;For(i,1,n){For(j,1,n){binom[i][j]=binom[i-1][j-1];Add(binom[i][j],binom[i-1][j]);}}
    fac[0]=1;For(i,1,n){fac[i]=i;(fac[i]*=fac[i-1])%=mod;}
    For(i,1,n)
    {
        if(vis[i][0]==false)
        {
            ++tot;int it=i,type=0,now_len=0;
            while(it<=n){vis[it][type]=true;++now_len;it+=k;type^=1;if(it>n)break;}
            chain[tot].len=now_len;
        }
        if(vis[i][1]==false)
        {
            ++tot;int it=i,type=1,now_len=0;
            while(it<=n){vis[it][type]=true;++now_len;it+=k;type^=1;if(it>n)break;}
            chain[tot].len=now_len;
        }
    }
    For(i,1,tot)
    {
        chain[i].f.resize(chain[i].len);
        int lim=(chain[i].len-1);
        For(edge_cnt,0,lim)chain[i].f[edge_cnt]=binom[chain[i].len-edge_cnt][edge_cnt];
    }
    poly prod_f=chain[1].f;For(i,2,tot)prod_f=(prod_f*chain[i].f);
    {int len=(prod_f.size()-1);For(i,len+1,n)prod_f.emplace_back(0);};
    ll ans=0;For(i,0,n){ll delta=prod_f[i];(delta*=fac[n-i])%=mod;if(i&1)Sub(ans,delta);else Add(ans,delta);}cout<<ans;return 0;
}

提出情報

提出日時
問題 D - ~K Perm Counting
ユーザ llzer
言語 C++ 20 (gcc 12.2)
得点 900
コード長 1988 Byte
結果 AC
実行時間 28 ms
メモリ 35300 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 900 / 900
結果
AC × 5
AC × 28
セット名 テストケース
Sample example0, example1, example2, example3, example4
All example0, example1, example2, example3, example4, handmade0, handmade1, handmade2, handmade3, handmade4, handmade5, handmade6, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, rand0, rand1, rand2, rand3, rand4, small0, small1, small2, supersmall0, supersmall1, supersmall2
ケース名 結果 実行時間 メモリ
example0 AC 1 ms 3584 KiB
example1 AC 1 ms 3564 KiB
example2 AC 1 ms 3664 KiB
example3 AC 1 ms 3616 KiB
example4 AC 3 ms 6848 KiB
handmade0 AC 1 ms 3652 KiB
handmade1 AC 22 ms 35044 KiB
handmade2 AC 15 ms 35300 KiB
handmade3 AC 20 ms 33204 KiB
handmade4 AC 14 ms 32596 KiB
handmade5 AC 28 ms 35252 KiB
handmade6 AC 28 ms 35176 KiB
maxrand0 AC 20 ms 33752 KiB
maxrand1 AC 23 ms 33844 KiB
maxrand2 AC 24 ms 34604 KiB
maxrand3 AC 26 ms 33672 KiB
maxrand4 AC 15 ms 33740 KiB
rand0 AC 26 ms 34984 KiB
rand1 AC 4 ms 9084 KiB
rand2 AC 4 ms 10276 KiB
rand3 AC 1 ms 4108 KiB
rand4 AC 18 ms 31792 KiB
small0 AC 2 ms 5548 KiB
small1 AC 1 ms 4600 KiB
small2 AC 2 ms 5244 KiB
supersmall0 AC 1 ms 3576 KiB
supersmall1 AC 1 ms 3656 KiB
supersmall2 AC 1 ms 3656 KiB