#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 6007, MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
n %= MOD;
if (n < 0) return n + MOD;
else return n;
}
int fp(int a, int p) {
int ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
int f[N], inv[N];
void prec() {
f[0] = 1;
for (int i = 1; i < N; ++i)
f[i] = mod(f[i - 1] * i);
inv[N - 1] = fp(f[N - 1], MOD - 2);
for (int i = N - 2; i >= 0; --i)
inv[i] = mod(inv[i + 1] * (i + 1));
}
int C(int n, int k) {
if (n < k)
return 0;
return mod(f[n] * mod(inv[k] * inv[n - k]));
}
void add(int &a, int b) { a = mod(a + b); }
int one[N][N];
int par[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n, m;
cin >> n >> m;
prec();
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
one[i][j] = 1;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
one[i][j] = 0;
add(one[i][j], one[i-1][j]);
add(one[i][j], one[i-1][j-1]*mod(j*4));
}
}
par[0] = 1;
for (int i = 2; i < N; i += 2)
par[i] = mod(par[i-2]*(i-1));
int ans = 0;
for (int hor = 0; hor <= n; ++hor) {
for (int ver = 0; ver <= m; ++ver) {
int rem_n = n - hor - 2 * ver;
int rem_m = m - ver - 2 * hor;
if (rem_n >= 0 && rem_m >= 0) {
int fc = mod(C(n, rem_n) * C(m, rem_m));
fc = mod(fc * mod(C(hor + 2 * ver, hor) * C(ver + 2 * hor, ver)));
fc = mod(fc * par[2 * ver]);
fc = mod(fc * par[2 * hor]);
fc = mod(fc * f[ver]);
fc = mod(fc * f[hor]);
add(ans, one[rem_n][rem_m] * fc);
}
}
}
cout << mod(ans-1) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
1408 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
1536 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
6 ms |
1664 KB |
Output is correct |
9 |
Correct |
5 ms |
1024 KB |
Output is correct |
10 |
Correct |
6 ms |
1920 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
1408 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
1536 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
6 ms |
1664 KB |
Output is correct |
9 |
Correct |
5 ms |
1024 KB |
Output is correct |
10 |
Correct |
6 ms |
1920 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
2432 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
9984 KB |
Output is correct |
15 |
Correct |
168 ms |
55576 KB |
Output is correct |
16 |
Correct |
9 ms |
4224 KB |
Output is correct |
17 |
Correct |
26 ms |
13056 KB |
Output is correct |
18 |
Correct |
39 ms |
17280 KB |
Output is correct |
19 |
Correct |
199 ms |
63352 KB |
Output is correct |
20 |
Correct |
161 ms |
51200 KB |
Output is correct |
21 |
Correct |
90 ms |
33920 KB |
Output is correct |
22 |
Correct |
91 ms |
35712 KB |
Output is correct |
23 |
Correct |
35 ms |
27392 KB |
Output is correct |
24 |
Correct |
256 ms |
83192 KB |
Output is correct |
25 |
Correct |
181 ms |
63224 KB |
Output is correct |
26 |
Correct |
215 ms |
71672 KB |
Output is correct |
27 |
Correct |
243 ms |
80120 KB |
Output is correct |