Submission #3447223


Source Code Expand

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2005 + 10;
const int mod = 924844033;

int n, m, tot;
int tag[N], vis[N * 2];
int dp[N], g[N], fac[N], c[N][N], f[N * 2][N][2][2];

inline void Add(int &x, int y) {
	x = (x + y >= mod) ? (x + y - mod) : (x + y);
}

int main() {
	cin >> n >> m;
	c[0][0] = 1;
	for (int i = 1; i < N; ++i) {
		c[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			Add(c[i][j], c[i - 1][j]);
			Add(c[i][j], c[i - 1][j - 1]);
		}
	}
	fac[0] = 1;
	for (int i = 1; i < N; ++i)
		fac[i] = 1LL * fac[i - 1] * i % mod;
	for (int i = 1; i <= n; ++i) {
		if (vis[i]) continue;
		for (int j = i; j <= n; j += m) {
			tag[++tot] = 1;
			vis[j] = 1;
		}
		tag[tot] = 0;
	}
	f[0][0][1][0] = 1;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int a = 0; a < 2; ++a) {
				for (int b = 0; b < 2; ++b) {
					int t = f[i][j][a][b];
					Add(f[i + 1][j][b][0], t);
					if (tag[i + 1])
						Add(f[i + 1][j + 1][b][1], t);
					if (tag[i])
						if (!a) Add(f[i + 1][j + 1][b][0], t);
				}
			}
		}
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < 2; ++j) {
			Add(dp[i], f[n][i][j][0]);
		}
	}
	// cout << n << endl;
	// // for (int i = 0; i <= n; ++i)
	// 	cout << dp[i] << ' ';
	// puts("");
	int ans = fac[n];
	for (int i = n; i >= 1; --i) {
		g[i] = 1LL * dp[i] * fac[n - i] % mod;
		if (i & 1) ans -= g[i];
		else ans += g[i];
		if (ans >= mod) ans -= mod;
		if (ans < 0) ans += mod;
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User Vexoben
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1572 Byte
Status AC
Exec Time 73 ms
Memory 81536 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 9 ms 18048 KB
example1 AC 9 ms 18048 KB
example2 AC 9 ms 18176 KB
example3 AC 9 ms 18048 KB
example4 AC 14 ms 31104 KB
handmade0 AC 9 ms 18048 KB
handmade1 AC 73 ms 81536 KB
handmade2 AC 55 ms 81536 KB
handmade3 AC 67 ms 77440 KB
handmade4 AC 49 ms 77440 KB
handmade5 AC 73 ms 81536 KB
handmade6 AC 73 ms 81536 KB
maxrand0 AC 56 ms 79616 KB
maxrand1 AC 63 ms 79488 KB
maxrand2 AC 66 ms 81536 KB
maxrand3 AC 68 ms 79488 KB
maxrand4 AC 52 ms 79488 KB
rand0 AC 69 ms 81536 KB
rand1 AC 17 ms 37376 KB
rand2 AC 18 ms 39552 KB
rand3 AC 10 ms 20480 KB
rand4 AC 50 ms 75392 KB
small0 AC 12 ms 26880 KB
small1 AC 10 ms 22656 KB
small2 AC 11 ms 24704 KB
supersmall0 AC 9 ms 18048 KB
supersmall1 AC 9 ms 18048 KB
supersmall2 AC 9 ms 18048 KB