Submission #499848

# Submission time Handle Problem Language Result Execution time Memory
499848 2021-12-29T19:23:16 Z keta_tsimakuridze NoM (RMI21_nom) C++14
52 / 100
35 ms 10112 KB
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 2000 + 5, mod = 1e9 + 7; // !
int t, dp[N][N], fact[N], invfact[N],x[N],d[N];
int pwr(int u,int v) {
	int ans = 1;
	while(v) {
		if(v % 2) ans = ans * u % mod;
		v /= 2; u = u * u % mod;
	}
	return ans;
}
int A(int a,int b) {
	if(a < 0) return 0;
	if(a < b) return 0;
	return fact[a] * invfact[a - b] % mod;
}
int c(int a,int b) {
	if(a < b || a < 0) return 0;
	return fact[a] * invfact[a - b] % mod * invfact[b] % mod;
}
main(){
	int n , m;
	cin >> n >> m;
	for(int i = 1; i <= 2 * n; i++) {
		x[i % m + 1]++;
	}
	fact[0] = invfact[0] = 1;
	for(int i = 1; i <= 2 * n; i++) fact[i] = fact[i - 1] * i % mod,
								invfact[i] = invfact[i - 1] * pwr(i, mod - 2) % mod;
	
	int cur = 0;
	dp[0][0] = 1;
	for(int i = 1; i <= m; i++) {
		for(int j = 0; j <= cur; j++) {
			for(int k = 0; k <= x[i]; k += 2) {
				dp[i][j + k / 2] += dp[i - 1][j] * A(x[i], k) % mod * c(n - j, k / 2) % mod;
				dp[i][j + k / 2] %= mod;
			}
		}
	//	cout << dp[i][2] <<" "<< c[i] << endl;
		cur += x[i];
	//	for(int j = 0; j <= cur; j++) cout<<dp[i][j] <<" "; cout << endl;
	}
	
	for(int i = n; i >= 0; i--) {
		d[i] = dp[m][i] * fact[2 * n - i * 2] % mod; 
		for(int j = i + 1; j <= n; j++) {
			d[i] -=  d[j] * c(j, i) % mod;
			d[i] += mod; d[i] %= mod;
		}
	}
	cout << d[0];
}

Compilation message

Main.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 540 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 540 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
21 Correct 1 ms 716 KB Output is correct
22 Correct 3 ms 1832 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 3 ms 1836 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 4 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 540 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
21 Correct 1 ms 716 KB Output is correct
22 Correct 3 ms 1832 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 3 ms 1836 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 4 ms 2124 KB Output is correct
28 Correct 6 ms 420 KB Output is correct
29 Correct 10 ms 3316 KB Output is correct
30 Correct 13 ms 5816 KB Output is correct
31 Correct 6 ms 460 KB Output is correct
32 Correct 11 ms 3548 KB Output is correct
33 Correct 19 ms 6728 KB Output is correct
34 Correct 24 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 540 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
21 Correct 1 ms 716 KB Output is correct
22 Correct 3 ms 1832 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 3 ms 1836 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 4 ms 2124 KB Output is correct
28 Correct 6 ms 420 KB Output is correct
29 Correct 10 ms 3316 KB Output is correct
30 Correct 13 ms 5816 KB Output is correct
31 Correct 6 ms 460 KB Output is correct
32 Correct 11 ms 3548 KB Output is correct
33 Correct 19 ms 6728 KB Output is correct
34 Correct 24 ms 10112 KB Output is correct
35 Incorrect 35 ms 508 KB Output isn't correct
36 Halted 0 ms 0 KB -