/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 1e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
ll n, m, ifact[N], fact[N], dp[4005][4005], sz[N];
ll C(ll r, ll k) {
if(r<0 || r>k) return 0;
return MOD(fact[k] * MOD(ifact[r] * ifact[k-r]));
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m;
fact[0] = ifact[0] = 1;
for(ll i=1; i<N; i++) {
fact[i] = MOD(fact[i-1] * i);
ifact[i] = poww(fact[i], Mod-2);
}
for(int i=1; i<=m; i++) sz[i] = (2*n-i+1+m-1)/m;
ll ans = 0;
for(int j=0; j<=m; j++) dp[0][j] = 1;
for(int i=1; i<=n; i++) {
for(ll j=1; j<=m; j++) {
for(ll num=0; num<=i&&2*num<=sz[j]; num++) {
dp[i][j] = MOD(dp[i][j] + dp[i-num][j-1]*MOD(C(num,i) * MOD(fact[2*num]*C(2*num,sz[j]))));
}
}
}
for(ll j=0; j<=n; j++) {
ll res = MOD(C(j,n)*dp[j][m])*fact[2*n-2*j];
if(j%2==0) ans = MOD(ans + res);
else ans = MOD(ans - res);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
4792 KB |
Output is correct |
2 |
Correct |
39 ms |
4952 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
5204 KB |
Output is correct |
5 |
Correct |
39 ms |
4948 KB |
Output is correct |
6 |
Correct |
39 ms |
4900 KB |
Output is correct |
7 |
Correct |
39 ms |
4932 KB |
Output is correct |
8 |
Correct |
39 ms |
4948 KB |
Output is correct |
9 |
Correct |
41 ms |
4816 KB |
Output is correct |
10 |
Correct |
40 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
4792 KB |
Output is correct |
2 |
Correct |
39 ms |
4952 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
5204 KB |
Output is correct |
5 |
Correct |
39 ms |
4948 KB |
Output is correct |
6 |
Correct |
39 ms |
4900 KB |
Output is correct |
7 |
Correct |
39 ms |
4932 KB |
Output is correct |
8 |
Correct |
39 ms |
4948 KB |
Output is correct |
9 |
Correct |
41 ms |
4816 KB |
Output is correct |
10 |
Correct |
40 ms |
4952 KB |
Output is correct |
11 |
Correct |
40 ms |
5204 KB |
Output is correct |
12 |
Correct |
39 ms |
4948 KB |
Output is correct |
13 |
Correct |
39 ms |
4952 KB |
Output is correct |
14 |
Correct |
40 ms |
5012 KB |
Output is correct |
15 |
Correct |
40 ms |
4948 KB |
Output is correct |
16 |
Correct |
40 ms |
5128 KB |
Output is correct |
17 |
Correct |
39 ms |
4948 KB |
Output is correct |
18 |
Correct |
40 ms |
4948 KB |
Output is correct |
19 |
Correct |
40 ms |
5048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
4792 KB |
Output is correct |
2 |
Correct |
39 ms |
4952 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
5204 KB |
Output is correct |
5 |
Correct |
39 ms |
4948 KB |
Output is correct |
6 |
Correct |
39 ms |
4900 KB |
Output is correct |
7 |
Correct |
39 ms |
4932 KB |
Output is correct |
8 |
Correct |
39 ms |
4948 KB |
Output is correct |
9 |
Correct |
41 ms |
4816 KB |
Output is correct |
10 |
Correct |
40 ms |
4952 KB |
Output is correct |
11 |
Correct |
40 ms |
5204 KB |
Output is correct |
12 |
Correct |
39 ms |
4948 KB |
Output is correct |
13 |
Correct |
39 ms |
4952 KB |
Output is correct |
14 |
Correct |
40 ms |
5012 KB |
Output is correct |
15 |
Correct |
40 ms |
4948 KB |
Output is correct |
16 |
Correct |
40 ms |
5128 KB |
Output is correct |
17 |
Correct |
39 ms |
4948 KB |
Output is correct |
18 |
Correct |
40 ms |
4948 KB |
Output is correct |
19 |
Correct |
40 ms |
5048 KB |
Output is correct |
20 |
Correct |
41 ms |
5460 KB |
Output is correct |
21 |
Correct |
41 ms |
5460 KB |
Output is correct |
22 |
Correct |
44 ms |
6228 KB |
Output is correct |
23 |
Correct |
42 ms |
5716 KB |
Output is correct |
24 |
Correct |
44 ms |
6332 KB |
Output is correct |
25 |
Correct |
45 ms |
6096 KB |
Output is correct |
26 |
Correct |
43 ms |
5716 KB |
Output is correct |
27 |
Correct |
46 ms |
6616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
4792 KB |
Output is correct |
2 |
Correct |
39 ms |
4952 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
5204 KB |
Output is correct |
5 |
Correct |
39 ms |
4948 KB |
Output is correct |
6 |
Correct |
39 ms |
4900 KB |
Output is correct |
7 |
Correct |
39 ms |
4932 KB |
Output is correct |
8 |
Correct |
39 ms |
4948 KB |
Output is correct |
9 |
Correct |
41 ms |
4816 KB |
Output is correct |
10 |
Correct |
40 ms |
4952 KB |
Output is correct |
11 |
Correct |
40 ms |
5204 KB |
Output is correct |
12 |
Correct |
39 ms |
4948 KB |
Output is correct |
13 |
Correct |
39 ms |
4952 KB |
Output is correct |
14 |
Correct |
40 ms |
5012 KB |
Output is correct |
15 |
Correct |
40 ms |
4948 KB |
Output is correct |
16 |
Correct |
40 ms |
5128 KB |
Output is correct |
17 |
Correct |
39 ms |
4948 KB |
Output is correct |
18 |
Correct |
40 ms |
4948 KB |
Output is correct |
19 |
Correct |
40 ms |
5048 KB |
Output is correct |
20 |
Correct |
41 ms |
5460 KB |
Output is correct |
21 |
Correct |
41 ms |
5460 KB |
Output is correct |
22 |
Correct |
44 ms |
6228 KB |
Output is correct |
23 |
Correct |
42 ms |
5716 KB |
Output is correct |
24 |
Correct |
44 ms |
6332 KB |
Output is correct |
25 |
Correct |
45 ms |
6096 KB |
Output is correct |
26 |
Correct |
43 ms |
5716 KB |
Output is correct |
27 |
Correct |
46 ms |
6616 KB |
Output is correct |
28 |
Correct |
62 ms |
7508 KB |
Output is correct |
29 |
Correct |
65 ms |
9032 KB |
Output is correct |
30 |
Correct |
67 ms |
10064 KB |
Output is correct |
31 |
Correct |
62 ms |
7448 KB |
Output is correct |
32 |
Correct |
67 ms |
9300 KB |
Output is correct |
33 |
Correct |
73 ms |
10976 KB |
Output is correct |
34 |
Correct |
99 ms |
14376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
4792 KB |
Output is correct |
2 |
Correct |
39 ms |
4952 KB |
Output is correct |
3 |
Correct |
40 ms |
4952 KB |
Output is correct |
4 |
Correct |
39 ms |
5204 KB |
Output is correct |
5 |
Correct |
39 ms |
4948 KB |
Output is correct |
6 |
Correct |
39 ms |
4900 KB |
Output is correct |
7 |
Correct |
39 ms |
4932 KB |
Output is correct |
8 |
Correct |
39 ms |
4948 KB |
Output is correct |
9 |
Correct |
41 ms |
4816 KB |
Output is correct |
10 |
Correct |
40 ms |
4952 KB |
Output is correct |
11 |
Correct |
40 ms |
5204 KB |
Output is correct |
12 |
Correct |
39 ms |
4948 KB |
Output is correct |
13 |
Correct |
39 ms |
4952 KB |
Output is correct |
14 |
Correct |
40 ms |
5012 KB |
Output is correct |
15 |
Correct |
40 ms |
4948 KB |
Output is correct |
16 |
Correct |
40 ms |
5128 KB |
Output is correct |
17 |
Correct |
39 ms |
4948 KB |
Output is correct |
18 |
Correct |
40 ms |
4948 KB |
Output is correct |
19 |
Correct |
40 ms |
5048 KB |
Output is correct |
20 |
Correct |
41 ms |
5460 KB |
Output is correct |
21 |
Correct |
41 ms |
5460 KB |
Output is correct |
22 |
Correct |
44 ms |
6228 KB |
Output is correct |
23 |
Correct |
42 ms |
5716 KB |
Output is correct |
24 |
Correct |
44 ms |
6332 KB |
Output is correct |
25 |
Correct |
45 ms |
6096 KB |
Output is correct |
26 |
Correct |
43 ms |
5716 KB |
Output is correct |
27 |
Correct |
46 ms |
6616 KB |
Output is correct |
28 |
Correct |
62 ms |
7508 KB |
Output is correct |
29 |
Correct |
65 ms |
9032 KB |
Output is correct |
30 |
Correct |
67 ms |
10064 KB |
Output is correct |
31 |
Correct |
62 ms |
7448 KB |
Output is correct |
32 |
Correct |
67 ms |
9300 KB |
Output is correct |
33 |
Correct |
73 ms |
10976 KB |
Output is correct |
34 |
Correct |
99 ms |
14376 KB |
Output is correct |
35 |
Correct |
187 ms |
11600 KB |
Output is correct |
36 |
Correct |
261 ms |
34872 KB |
Output is correct |
37 |
Correct |
184 ms |
11468 KB |
Output is correct |
38 |
Correct |
202 ms |
21616 KB |
Output is correct |
39 |
Correct |
216 ms |
29048 KB |
Output is correct |
40 |
Correct |
332 ms |
43440 KB |
Output is correct |