#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) {
for (int k = 0; k <= i && k <= j; ++k) {
add(one[i][j], mod(C(i,k)*C(j,k))*mod(f[k]*fp(4,k)));
}
}
}
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 |
24 ms |
896 KB |
Output is correct |
6 |
Correct |
41 ms |
1528 KB |
Output is correct |
7 |
Correct |
39 ms |
1016 KB |
Output is correct |
8 |
Correct |
23 ms |
1656 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
118 ms |
1912 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
449 ms |
2668 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 |
24 ms |
896 KB |
Output is correct |
6 |
Correct |
41 ms |
1528 KB |
Output is correct |
7 |
Correct |
39 ms |
1016 KB |
Output is correct |
8 |
Correct |
23 ms |
1656 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
118 ms |
1912 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
449 ms |
2668 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
11 ms |
9984 KB |
Output is correct |
15 |
Execution timed out |
2085 ms |
4728 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |