提出 #25477186


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
	int s=1,a=0;
	char c=getchar();
	while(!isdigit(c)) {
		if(c=='-') s=-s;
		c=getchar();
	}
	while(isdigit(c)) {
		a=(a<<3)+(a<<1)+c-'0';
		c=getchar();
	}
	return s*a;
}
const int N=5e3+8,Mod=924844033;
int n,k,jc[N],f[N][N][2],vis[N],tot;
void init() {
	jc[0]=1;
	for(int i=1; i<=n; i++) {
		jc[i]=jc[i-1]*i%Mod;
	}
	for(int i=1; i<=k; i++) {
		for(int t=1; t<=2; t++) {
			for(int j=i; j<=n; j+=k) {
				tot++;
				if(j!=i) vis[tot]=1;
			}
		}
	}
}
signed main() {
	n=read(),k=read();
	init();
	f[0][0][0]=1;
	for(int i=1; i<=(n<<1); i++) {
		for(int j=0; j<=n; j++) {
			f[i][j][0]=(f[i-1][j][0]+f[i-1][j][1])%Mod;
			if(vis[i]&&j>0) f[i][j][1]=f[i-1][j-1][0];
		}
	}
	int ans=0;
	for(int i=0; i<=n; i++) {
		if(i&1) ans=(ans-(f[n<<1][i][0]+f[n<<1][i][1])*jc[n-i]%Mod+Mod)%Mod;
		else ans=(ans+(f[n<<1][i][0]+f[n<<1][i][1])*jc[n-i]%Mod)%Mod;
	}
	printf("%lld\n",ans);
	return 0;
}

提出情報

提出日時
問題 D - ~K Perm Counting
ユーザ rpdg
言語 C++ (GCC 9.2.1)
得点 900
コード長 1021 Byte
結果 AC
実行時間 100 ms
メモリ 144720 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 8 ms 3560 KiB
example1 AC 4 ms 3716 KiB
example2 AC 3 ms 3508 KiB
example3 AC 2 ms 3704 KiB
example4 AC 15 ms 12728 KiB
handmade0 AC 2 ms 3736 KiB
handmade1 AC 100 ms 144720 KiB
handmade2 AC 94 ms 144696 KiB
handmade3 AC 82 ms 129752 KiB
handmade4 AC 83 ms 123736 KiB
handmade5 AC 94 ms 144660 KiB
handmade6 AC 91 ms 144680 KiB
maxrand0 AC 89 ms 132208 KiB
maxrand1 AC 87 ms 135408 KiB
maxrand2 AC 89 ms 140288 KiB
maxrand3 AC 88 ms 132280 KiB
maxrand4 AC 86 ms 131916 KiB
rand0 AC 91 ms 144256 KiB
rand1 AC 18 ms 20572 KiB
rand2 AC 21 ms 24572 KiB
rand3 AC 3 ms 4676 KiB
rand4 AC 78 ms 117772 KiB
small0 AC 9 ms 8976 KiB
small1 AC 8 ms 5832 KiB
small2 AC 6 ms 7980 KiB
supersmall0 AC 2 ms 3700 KiB
supersmall1 AC 2 ms 3504 KiB
supersmall2 AC 2 ms 3660 KiB