Submission #1365901


Source Code Expand

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read()
{
	int t=1,sum=0;char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		sum=sum*10+ch-'0',ch=getchar();
	return t*sum;
}
const int Max=2e3+10,mod=924844033;
int f[Max<<1][Max][2],g[Max],fac[Max],vis[Max][2],a[Max<<1],n,m,tot;
int main()
{
	int i,j,x,y;
	n=read(); m=read();
	for(i=1;i<=n;i++)
		for(j=0;j<2;j++) if(!vis[i][j])
		{
			int len=0;
			for(x=i,y=j;x<=n;x+=m,y^=1)
				vis[x][y]=1,len++;
			tot+=len;
			a[tot]=1;
		}
	f[0][0][1]=1;
	for(i=1;i<=tot;i++)
		for(j=0;j<=i/2;j++)
		{
			f[i][j][0]=(f[i-1][j][0]+f[i-1][j][1])%mod;
			if(j&&!a[i-1])
				f[i][j][1]=f[i-1][j-1][0];
		}
	for(i=0;i<=n;i++) g[i]=(f[tot][i][0]+f[tot][i][1])%mod;
	for(fac[0]=i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%mod;
	int ans=0;
	for(i=0;i<=n;i++)
		if(i&1)
			ans=(ans-1LL*g[i]*fac[n-i]%mod)%mod;
		else 
			ans=(ans+1LL*g[i]*fac[n-i]%mod)%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User c_2h
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1072 Byte
Status AC
Exec Time 22 ms
Memory 61568 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 13056 KB
handmade0 AC 1 ms 128 KB
handmade1 AC 22 ms 61568 KB
handmade2 AC 21 ms 61568 KB
handmade3 AC 20 ms 58112 KB
handmade4 AC 19 ms 58112 KB
handmade5 AC 22 ms 61568 KB
handmade6 AC 22 ms 61568 KB
maxrand0 AC 20 ms 60160 KB
maxrand1 AC 20 ms 60160 KB
maxrand2 AC 21 ms 60544 KB
maxrand3 AC 21 ms 60160 KB
maxrand4 AC 20 ms 60160 KB
rand0 AC 22 ms 61312 KB
rand1 AC 5 ms 19200 KB
rand2 AC 6 ms 21248 KB
rand3 AC 1 ms 2816 KB
rand4 AC 18 ms 56064 KB
small0 AC 2 ms 8960 KB
small1 AC 2 ms 4864 KB
small2 AC 2 ms 6912 KB
supersmall0 AC 1 ms 128 KB
supersmall1 AC 1 ms 256 KB
supersmall2 AC 1 ms 256 KB