Submission #1460552


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 924844033;

const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
ll fac[4010], invfac[4010];

ll potmod(ll a, ll b)
{
	ll res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * a ) % mod;
		a = (a * a)%mod;
		b /= 2;
	}
	return res;
}

inline ll binom(int n, int k)
{
	return fac[n] * invfac[k] % mod * invfac[n - k] % mod;
}
ll q[4010], c[4010], u, M[4010];

void mul(int x)
{
	int v = (x / 2) + 1;
	FOR(i, 0, v-1) q[i] = binom(x-i, i);
	FOR(i, 0, u+v-1) c[i] = 0;
	
	FOR(i, 0, u-1)
		FOR(j, 0, v-1) c[i+j] += (ll)M[i] * q[j], c[i+j]%=mod;
	
	FOR(i, 0, u+v-1) M[i] = c[i]; u += v-1;
}
int n, k;

int main()
{
	M[0] = 1; u = 1;
	fac[0] = 1; invfac[0] = 1;
	FOR(i, 1, 4000) 
	{
		fac[i] = fac[i-1] * i % mod;
		invfac[i] = potmod(fac[i], mod - 2);
	}
	boost;
	cin >> n >> k;
	FOR(i, 1, k)
	{
		int c = i, cnt = 0;
		while (c <= n) c+=k, ++cnt;
		mul(cnt);
		mul(cnt);
	}
	ll res = 0;
	for (int i=0; i<=n; ++i)
	{
		ll tmp = fac[n - i] * M[i]%mod;
		if (i & 1) res = (res + mod - tmp);
		else res += tmp;
		while (res >= mod) res -= mod;
	}
	cout << res;
	
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User Miyukine
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1757 Byte
Status AC
Exec Time 11 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 2 ms 384 KB
example1 AC 2 ms 384 KB
example2 AC 2 ms 384 KB
example3 AC 2 ms 384 KB
example4 AC 2 ms 384 KB
handmade0 AC 2 ms 384 KB
handmade1 AC 4 ms 384 KB
handmade2 AC 2 ms 384 KB
handmade3 AC 4 ms 384 KB
handmade4 AC 2 ms 384 KB
handmade5 AC 7 ms 384 KB
handmade6 AC 7 ms 384 KB
maxrand0 AC 10 ms 384 KB
maxrand1 AC 11 ms 384 KB
maxrand2 AC 10 ms 384 KB
maxrand3 AC 6 ms 384 KB
maxrand4 AC 4 ms 384 KB
rand0 AC 10 ms 384 KB
rand1 AC 3 ms 384 KB
rand2 AC 2 ms 384 KB
rand3 AC 2 ms 384 KB
rand4 AC 9 ms 384 KB
small0 AC 2 ms 384 KB
small1 AC 2 ms 384 KB
small2 AC 2 ms 384 KB
supersmall0 AC 2 ms 384 KB
supersmall1 AC 2 ms 384 KB
supersmall2 AC 2 ms 384 KB