Submission #1691822


Source Code Expand

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 2005;
const int mod = 924844033;

int h[maxn][maxn];
int g[maxn][maxn];
int f[maxn],e[maxn],v[maxn];
int n,fac[maxn],inc[maxn],sz[maxn],K;

LL fpm(LL p,LL k) {
	LL res=1ll;
	while (k) {
		if (k&1) (res*=p)%=mod;
		(p*=p)%=mod;k>>=1;
	}
	return res;
}
LL comb(int n,int m) {
	return (LL)fac[n]*inc[m]%mod*(LL)inc[n-m]%mod;
}
int main()
{
	#ifdef Amberframe
		freopen("agc005d.in","r",stdin);
		freopen("agc005d.out","w",stdout);
	#endif
	scanf("%d %d",&n,&K);fac[0]=inc[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (i-2*K<=0) {
			sz[i]=1;g[i][0]=1;g[i][1]=(i>K);h[i][1]=(i+K<=n);
		}
		else {
			int o=i-2*K;sz[i]=sz[o]+1;
			for (int j=0;j<=sz[i];j++)
				g[i][j]=(g[o][j]+h[o][j])%mod;
			for (int j=1;j<=sz[i];j++)
				g[i][j]=(g[i][j]+g[o][j-1])%mod;
			if (i+K>n) continue;
			for (int j=1;j<=sz[i];j++)
				h[i][j]=(g[o][j-1]+h[o][j-1])%mod;
		}
	}
	
	for (int i=1;i<=n;i++) fac[i]=(LL)fac[i-1]*i%mod;
	inc[n]=fpm(fac[n],mod-2);
	for (int i=n;i>=2;i--) inc[i-1]=(LL)inc[i]*i%mod;
	
	f[0]=1;int sum=0;
	for (int i=1;i<=n;i++)
	if (i+2*K>n) {
		for (int k=sz[i];k>=0;k--)
			e[k]=(h[i][k]+g[i][k])%mod;
		for (int k=sum+sz[i];k>=0;k--) v[k]=0;
		for (int j=sum;j>=0;j--)
		for (int k=sz[i];k>=0;k--)
			v[j+k]=(v[j+k]+(LL)f[j]*e[k])%mod;
		for (int k=sum+sz[i];k>=0;k--) f[k]=v[k];
		sum+=sz[i];
	}
	
	for (int i=0;i<=n;i++)
		f[i]=(LL)f[i]*fac[n-i]%mod;
	for (int i=n-1;i>=0;i--)
	for (int j=i+1;j<=n;j++)
		f[i]=(f[i]-(LL)f[j]*comb(j,i))%mod;
	printf("%d",f[0]<0?f[0]+mod:f[0]);
	return 0;
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User Amberframe
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1705 Byte
Status AC
Exec Time 34 ms
Memory 30720 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&K);fac[0]=inc[0]=1;
                      ^

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 2 ms 2304 KB
example1 AC 2 ms 2304 KB
example2 AC 2 ms 2304 KB
example3 AC 2 ms 2304 KB
example4 AC 4 ms 9472 KB
handmade0 AC 2 ms 2304 KB
handmade1 AC 29 ms 30720 KB
handmade2 AC 34 ms 30336 KB
handmade3 AC 26 ms 30080 KB
handmade4 AC 29 ms 29952 KB
handmade5 AC 25 ms 30080 KB
handmade6 AC 25 ms 30208 KB
maxrand0 AC 31 ms 29952 KB
maxrand1 AC 30 ms 29952 KB
maxrand2 AC 30 ms 27904 KB
maxrand3 AC 24 ms 29952 KB
maxrand4 AC 31 ms 29952 KB
rand0 AC 29 ms 27904 KB
rand1 AC 7 ms 13568 KB
rand2 AC 7 ms 13568 KB
rand3 AC 2 ms 4736 KB
rand4 AC 28 ms 29952 KB
small0 AC 3 ms 7424 KB
small1 AC 3 ms 5120 KB
small2 AC 3 ms 7424 KB
supersmall0 AC 2 ms 2304 KB
supersmall1 AC 2 ms 2304 KB
supersmall2 AC 2 ms 2304 KB