#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")//,bmi,bmi2,lzcnt,popcnt
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using piii = pair<ll, pii>;
#define pb push_back
#define F first
#define S second
#define len(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define file freopen("connect.in", "r", stdin);freopen("connect.out", "w", stdout);
#define kill(x) {cout << x << '\n'; continue;}
#define int long long
const int maxn = 3e3 + 5, maxm = 2e5, LG = 20, MOD = 1e9+7;// 998244353
const ll inf = 6e18;
//priority_queue< int, vector<int>, greater<int>> pq; min heap
//priority_queue< int, vector<int>, less<int> > pq; max heap
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int h, w, dp[maxn][maxn];
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> h >> w;
for(int i = 0; i <= h; ++i) dp[i][0] = 1;
for(int i = 0; i <= w; ++i) dp[0][i] = 1;
dp[1][1] = 5;
for(int i = 2; i <= max(h, w); ++i) {
dp[1][i] = 4 + i-1 + dp[1][i-1];
dp[1][i] %= MOD;
dp[i][1] = dp[1][i];
}
for(int i = 2; i <= h; ++i)
for(int j = 2; j <= w; ++j) {
dp[i][j] = (4 * j * dp[i-1][j-1] % MOD);
dp[i][j] += ((j*(j-1)/2 % MOD) * dp[i-1][j-2] % MOD) % MOD;
dp[i][j] += ((j*(i-1) % MOD) * dp[i-2][j-1] % MOD) % MOD;
dp[i][j] += dp[i-1][j];
dp[i][j] %= MOD;
}
cout << dp[h][w] - 1;
}
// it was fun while it lasted
// ctrl + d
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
5 ms |
43352 KB |
Output is correct |
14 |
Correct |
7 ms |
55900 KB |
Output is correct |
15 |
Correct |
41 ms |
66140 KB |
Output is correct |
16 |
Correct |
7 ms |
37468 KB |
Output is correct |
17 |
Correct |
12 ms |
43944 KB |
Output is correct |
18 |
Correct |
13 ms |
33372 KB |
Output is correct |
19 |
Correct |
45 ms |
70236 KB |
Output is correct |
20 |
Correct |
36 ms |
58084 KB |
Output is correct |
21 |
Correct |
27 ms |
49752 KB |
Output is correct |
22 |
Correct |
25 ms |
51800 KB |
Output is correct |
23 |
Correct |
19 ms |
70492 KB |
Output is correct |
24 |
Correct |
59 ms |
70992 KB |
Output is correct |
25 |
Correct |
44 ms |
62040 KB |
Output is correct |
26 |
Correct |
58 ms |
68432 KB |
Output is correct |
27 |
Correct |
58 ms |
70232 KB |
Output is correct |