#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("trapv")
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
using namespace std;
///~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename H, typename T>
ostream& operator<<(ostream& os, pair<H, T> m){
return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H>
ostream& operator<<(ostream& os, vector<H> V){
os<<"{";
for(int i=0; i<V.size(); i++){
if(i)os<<" ";
os<<V[i];
}
os<<"}";
return os;
}
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
///~~~~~~~~~~~~~~~~~~~~~~~~~
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=3e3+5, INF=1e9+5, mod=1e9+7;
int pot(int a, int b){
if(!b)return 1;
if(b==1)return a;
ll c=pot(a, b/2);
c=(c*c)%mod;
if(b&1)c=(c*a)%mod;
return c;
}
int odw(int a){return pot(a, mod-2);}
int sil[N], sil2[N], odw2[N];
int dp[N][N];
int main(){
//BOOST;
sil[0]=1;
for(int i=1; i<N; i++)sil[i]=(sil[i-1]*1ll*i)%mod;
for(int i=1; i<N; i++)odw2[i]=odw(i);
for(int i=0; i<N; i++)sil2[i]=odw(sil[i]);
for(int i=0; i<N; i++)dp[0][i]=sil2[i];
for(int i=1; i<N; i++){
for(int j=0; j<N; j++){
dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
if(j+1<N)dp[i][j+1]=(4ll*dp[i-1][j])%mod;
}
for(int j=0; j<N; j++){
dp[i][j]=(dp[i][j]*1ll*odw2[i])%mod;
}
}
deb(4*dp[2][2]-mod);
int n, m;
cin>>n>>m;
ll ans=0;
for(int i=0; i<=n; i++){
for(int j=0; j<=m; j++){
int a=n-i-2*j, b=m-j-2*i;
if(a>=0 && b>=0){
ll part=dp[a][b];
part=(part*sil2[i])%mod;
part=(part*sil2[j])%mod;
part=(part*pot(odw2[2], i+j))%mod;
ans+=part;
//deb(i, j, a, b, part*12%mod, (48*part)%mod);
}
}
}
ans%=mod;
ans=(ans*sil[n])%mod;
ans=(ans*sil[m])%mod;
cout<<(ans+mod-1)%mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
35668 KB |
Output is correct |
2 |
Correct |
125 ms |
35672 KB |
Output is correct |
3 |
Correct |
117 ms |
35652 KB |
Output is correct |
4 |
Correct |
119 ms |
35660 KB |
Output is correct |
5 |
Correct |
133 ms |
35640 KB |
Output is correct |
6 |
Correct |
125 ms |
35660 KB |
Output is correct |
7 |
Correct |
117 ms |
35784 KB |
Output is correct |
8 |
Correct |
127 ms |
35676 KB |
Output is correct |
9 |
Correct |
120 ms |
35596 KB |
Output is correct |
10 |
Correct |
118 ms |
35684 KB |
Output is correct |
11 |
Correct |
120 ms |
35656 KB |
Output is correct |
12 |
Correct |
139 ms |
35644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
35668 KB |
Output is correct |
2 |
Correct |
125 ms |
35672 KB |
Output is correct |
3 |
Correct |
117 ms |
35652 KB |
Output is correct |
4 |
Correct |
119 ms |
35660 KB |
Output is correct |
5 |
Correct |
133 ms |
35640 KB |
Output is correct |
6 |
Correct |
125 ms |
35660 KB |
Output is correct |
7 |
Correct |
117 ms |
35784 KB |
Output is correct |
8 |
Correct |
127 ms |
35676 KB |
Output is correct |
9 |
Correct |
120 ms |
35596 KB |
Output is correct |
10 |
Correct |
118 ms |
35684 KB |
Output is correct |
11 |
Correct |
120 ms |
35656 KB |
Output is correct |
12 |
Correct |
139 ms |
35644 KB |
Output is correct |
13 |
Correct |
125 ms |
35600 KB |
Output is correct |
14 |
Correct |
119 ms |
35684 KB |
Output is correct |
15 |
Correct |
234 ms |
35660 KB |
Output is correct |
16 |
Correct |
130 ms |
35656 KB |
Output is correct |
17 |
Correct |
142 ms |
35656 KB |
Output is correct |
18 |
Correct |
145 ms |
35604 KB |
Output is correct |
19 |
Correct |
295 ms |
35676 KB |
Output is correct |
20 |
Correct |
231 ms |
35588 KB |
Output is correct |
21 |
Correct |
185 ms |
35564 KB |
Output is correct |
22 |
Correct |
192 ms |
35676 KB |
Output is correct |
23 |
Correct |
130 ms |
35672 KB |
Output is correct |
24 |
Correct |
323 ms |
35660 KB |
Output is correct |
25 |
Correct |
273 ms |
35676 KB |
Output is correct |
26 |
Correct |
297 ms |
35732 KB |
Output is correct |
27 |
Correct |
330 ms |
35784 KB |
Output is correct |