Submission #569171

# Submission time Handle Problem Language Result Execution time Memory
569171 2022-05-26T21:34:28 Z rawoti6303 NoM (RMI21_nom) C++14
100 / 100
100 ms 27852 KB
#include <bits/stdc++.h>

#define INF 1000000005
#define INFL 1000000000000000005ll
#define EPS 1e-6
#define pb push_back
#define pause system("pause")
#define exit exit(0)
#define endl '\n'

using namespace std;
using ull = unsigned long long;
using ll = long long;

typedef pair<ll, ll> pii;
const int N = 2005, MOD = 1e9 + 7;

int n, m, f[N], c[N][N], dp[N][N];

inline int add(int a, int b) {
	return a + b < MOD ? (a + b) : (a + b - MOD);
}

inline int mul(int a, int b) {
	return ((ll)a * b) % MOD;
}

inline void upd(int &a, int b) {
	a = add(a, b);
}

inline int bpow(int a, int b) {
	int ans = 1;
	while (b != 0) {
		if (b & 1)
			ans = mul(ans, a);
		a = mul(a, a), b >>= 1;
	}

	return ans;
}

int fact(int n) {
	int ans = 1;
	for (int i = 2; i <= n; ++i) {
		ans = mul(ans, i);
	}

	return ans;
}

int naive(int n, int m) {
	vector<int> p(2 * n);
	for (int i = 0; i < 2 * n; ++i) {
		p[i] = i + 1;
	}

	int ans = 0;
	do {
		bool ok = 1;
		for (int i = 0; ok && i < 2 * n; ++i) {
			for (int j = i + 1; j < 2 * n; ++j) {
				if (abs(p[i] - p[j]) == n) {
					ok &= ((j - i) % m) != 0;
					break;
				}
			}
		}

		ans += ok;
	} while (next_permutation(p.begin(), p.end()));
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> m;
	//cout << naive(n, m) << endl;
	for (int i = 0; i <= n; ++i) {
		c[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);
		}
	}

	for (int i = 0; i < 2 * n; ++i) {
		++f[i % m];
	}

	int sm = f[0], iter = 0;
	dp[0][f[0]] = mul(c[n][f[0]], bpow(2, f[0]));
	for (int i = 0; i < m - 1; ++i) {
		for (int j = 0; j <= sm; ++j) {
			for (int k = 0; k <= j && k <= f[i + 1]; ++k) {
				if (j - k + f[i + 1] - k > n || dp[i][j] == 0)
					continue;

				++iter;
				upd(dp[i + 1][j - k + f[i + 1] - k],
					mul(
						dp[i][j],
						mul(
							c[j][k],
							mul(
								c[n - (((sm - j) / 2) + j)][f[i + 1] - k],
								bpow(2, f[i + 1] - k)
							)
						)
					)
				);
			}
		}

		sm += f[i + 1];
	}

	int ans = dp[m - 1][0];
	for (int i = 0; i < m; ++i) {
		ans = mul(ans, fact(f[i]));
	}

	assert(iter <= 2e7);
	cout << ans << endl;
	//pause;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 864 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 864 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 3 ms 2588 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 3 ms 2516 KB Output is correct
26 Correct 2 ms 1492 KB Output is correct
27 Correct 3 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 864 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 3 ms 2588 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 3 ms 2516 KB Output is correct
26 Correct 2 ms 1492 KB Output is correct
27 Correct 3 ms 3028 KB Output is correct
28 Correct 9 ms 3636 KB Output is correct
29 Correct 11 ms 5460 KB Output is correct
30 Correct 9 ms 6740 KB Output is correct
31 Correct 12 ms 3668 KB Output is correct
32 Correct 12 ms 5844 KB Output is correct
33 Correct 11 ms 7636 KB Output is correct
34 Correct 24 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 864 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 3 ms 2588 KB Output is correct
23 Correct 2 ms 1492 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 3 ms 2516 KB Output is correct
26 Correct 2 ms 1492 KB Output is correct
27 Correct 3 ms 3028 KB Output is correct
28 Correct 9 ms 3636 KB Output is correct
29 Correct 11 ms 5460 KB Output is correct
30 Correct 9 ms 6740 KB Output is correct
31 Correct 12 ms 3668 KB Output is correct
32 Correct 12 ms 5844 KB Output is correct
33 Correct 11 ms 7636 KB Output is correct
34 Correct 24 ms 10616 KB Output is correct
35 Correct 61 ms 11256 KB Output is correct
36 Correct 66 ms 24012 KB Output is correct
37 Correct 60 ms 11084 KB Output is correct
38 Correct 46 ms 16904 KB Output is correct
39 Correct 46 ms 20936 KB Output is correct
40 Correct 100 ms 27852 KB Output is correct