Submission #1812054


Source Code Expand

//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=924844033;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
int n,k;
ll fac[2011];
bool pre[2011],nxt[2011];
ll dp0[2011],dp1[2011],ans[2011];
int anssz;
//dp0=dp0'(1+x)+dp1'
//dp1=(dp0'+dp1')x
ll mul_a[2011];
int mul(ll a[],int na,ll b[],int nb,ll c[])
{
	for(int i=0;i<=na+nb;i++)mul_a[i]=0;
	for(int i=0;i<=na;i++)
	{
		for(int j=0;j<=nb;j++)
		{
			mul_a[i+j]=(mul_a[i+j]+a[i]*b[j])%mod;
		}
	}
	for(int i=0;i<=na+nb;i++)c[i]=mul_a[i];
	return na+nb;
}
ll ndp0[2011],ndp1[2011];
void solve(int tn)
{
	memset(dp0,0,sizeof(dp0));
	memset(dp1,0,sizeof(dp1));
	dp0[0]=1;
	for(int i=1;i<=tn;i++)
	{
		memset(ndp0,0,sizeof(ndp0));
		memset(ndp1,0,sizeof(ndp1));
		for(int j=0;j<=i;j++)ndp0[j]=(dp0[j]+dp1[j])%mod;
		if(pre[i])for(int j=1;j<=i;j++)ndp0[j]=(ndp0[j]+dp0[j-1])%mod;
		if(nxt[i])for(int j=1;j<=i;j++)ndp1[j]=(dp0[j-1]+dp1[j-1])%mod;
		swap(dp0,ndp0);
		swap(dp1,ndp1);
	}
	for(int i=0;i<=tn;i++)dp0[i]=(dp0[i]+dp1[i])%mod;
	anssz=mul(dp0,tn,ans,anssz,ans);
}
int main()
{
	fac[0]=1;
	for(int i=1;i<=2005;i++)fac[i]=fac[i-1]*i%mod;
	cin>>n>>k;
	ans[0]=1;
	for(int i=1;i<=min(n,2*k);i++)
	{
		int tn=0;
		for(int j=i;j<=n;j+=2*k)
		{
			pre[++tn]=j-k>=1;
			nxt[tn]=j+k<=n;
		}
		solve(tn);
	}
	ll res=0;
	for(int i=0;i<=n;i++)
	{
		ll cur=ans[i]*fac[n-i]%mod;
		if(i&1)res-=cur;
		else res+=cur;
	}
	res=(res%mod+mod)%mod;
	cout<<res<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User fizzydavid
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2925 Byte
Status AC
Exec Time 22 ms
Memory 384 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 384 KB
example1 AC 1 ms 384 KB
example2 AC 1 ms 384 KB
example3 AC 1 ms 384 KB
example4 AC 3 ms 384 KB
handmade0 AC 1 ms 384 KB
handmade1 AC 17 ms 384 KB
handmade2 AC 22 ms 384 KB
handmade3 AC 16 ms 384 KB
handmade4 AC 20 ms 384 KB
handmade5 AC 14 ms 384 KB
handmade6 AC 14 ms 384 KB
maxrand0 AC 21 ms 384 KB
maxrand1 AC 21 ms 384 KB
maxrand2 AC 21 ms 384 KB
maxrand3 AC 13 ms 384 KB
maxrand4 AC 21 ms 384 KB
rand0 AC 18 ms 384 KB
rand1 AC 5 ms 384 KB
rand2 AC 6 ms 384 KB
rand3 AC 2 ms 384 KB
rand4 AC 19 ms 384 KB
small0 AC 3 ms 384 KB
small1 AC 2 ms 384 KB
small2 AC 3 ms 384 KB
supersmall0 AC 1 ms 384 KB
supersmall1 AC 1 ms 384 KB
supersmall2 AC 1 ms 384 KB