#include <bits/stdc++.h>
#pragma GCC target ("avx,avx2,fma")
#pragma GCC optimization ("O8")
#pragma GCC optimization ("unroll-loops")
#define X first
#define Y second
#define debug(x) cerr << #x << ": " << x << endl;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for (int i=l; i<r; i++)
#define repr(i,r,l) for (int i=r; i>=l; i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const long long int N=3e3+20,mod = 1e9+7,inf=2e18,dlt = 12250,maxm = 2e6;
int poww(ll a,int k){
if (!k) return 1;
if (k == 1) return a;
ll r = poww(a,k/2);
return (((r*r)%mod)*poww(a,k&1))%mod;
}
ll dp[N][N];
int main(){
int h,w;
cin >> h >> w;
rep(i,0,w+1){
dp[0][i] = 1;
dp[1][i] = 4*i+1+i*(i-1)/2;
}
rep(i,1,h+1){
dp[i][1] = 4*i+i*(i-1)/2+1;
dp[i][0] = 1;
}
rep(i,2,h+1){
rep(j,2,w+1){
dp[i][j] = dp[i-1][j]+1ll*j*(j-1)*dp[i-1][j-2]/2;
dp[i][j] %= mod;
dp[i][j] += j*((dp[i-1][j-1]*4+(i-1)*dp[i-2][j-1])%mod);
dp[i][j] %= mod;
}
}
cout << (mod-1+dp[h][w])%mod;
}
Compilation message
tents.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("O8")
|
tents.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
4 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
1320 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
2124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
1320 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
2124 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
6 ms |
9548 KB |
Output is correct |
15 |
Correct |
78 ms |
55080 KB |
Output is correct |
16 |
Correct |
7 ms |
4044 KB |
Output is correct |
17 |
Correct |
18 ms |
12748 KB |
Output is correct |
18 |
Correct |
25 ms |
16972 KB |
Output is correct |
19 |
Correct |
90 ms |
62916 KB |
Output is correct |
20 |
Correct |
70 ms |
50808 KB |
Output is correct |
21 |
Correct |
47 ms |
33732 KB |
Output is correct |
22 |
Correct |
52 ms |
35324 KB |
Output is correct |
23 |
Correct |
30 ms |
26952 KB |
Output is correct |
24 |
Correct |
108 ms |
71108 KB |
Output is correct |
25 |
Correct |
89 ms |
61536 KB |
Output is correct |
26 |
Correct |
98 ms |
66908 KB |
Output is correct |
27 |
Correct |
104 ms |
69332 KB |
Output is correct |