Submission #7942347


Source Code Expand

#include<bits/stdc++.h>
typedef long long ll;
#define mod 924844033
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
int f[2010],fact[2010],ifact[2010];
int C(int n,int m){if(n<m)return 0;return 1ll*fact[n]*ifact[m]%mod*ifact[n-m]%mod;}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),K=gi();
	fact[0]=1;for(int i=1;i<=n;++i)fact[i]=1ll*fact[i-1]*i%mod;
	ifact[n]=pow(fact[n],mod-2);for(int i=n;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	f[0]=1;
	for(int l=1;l<=n&&l<=K*2;++l){
		int r=l;while(r+K*2<=n)r+=K*2;
		int cnt=(r-l)/K+(l>K)+(r+K<=n);
		for(int i=n;i;--i)
			for(int j=1;j*2-1<=cnt&&j<=i;++j)
				f[i]=(f[i]+1ll*f[i-j]*C(cnt-j+1,j))%mod;
	}
	int ans=0;
	for(int i=0,m=1;i<=n;++i,m=mod-m)ans=(ans+1ll*f[i]*m%mod*fact[n-i])%mod;
	printf("%d\n",ans);
	return 0;
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User test12345
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1040 Byte
Status AC
Exec Time 36 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 5
AC × 28
Set Name Test Cases
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
Case Name Status Exec Time Memory
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
example3 AC 1 ms 256 KB
example4 AC 3 ms 256 KB
handmade0 AC 1 ms 256 KB
handmade1 AC 27 ms 256 KB
handmade2 AC 4 ms 256 KB
handmade3 AC 24 ms 256 KB
handmade4 AC 4 ms 256 KB
handmade5 AC 34 ms 256 KB
handmade6 AC 35 ms 256 KB
maxrand0 AC 17 ms 256 KB
maxrand1 AC 31 ms 256 KB
maxrand2 AC 30 ms 256 KB
maxrand3 AC 32 ms 256 KB
maxrand4 AC 6 ms 256 KB
rand0 AC 36 ms 256 KB
rand1 AC 4 ms 256 KB
rand2 AC 2 ms 256 KB
rand3 AC 1 ms 256 KB
rand4 AC 15 ms 256 KB
small0 AC 2 ms 256 KB
small1 AC 2 ms 256 KB
small2 AC 2 ms 256 KB
supersmall0 AC 1 ms 256 KB
supersmall1 AC 1 ms 256 KB
supersmall2 AC 1 ms 256 KB