This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define eb emplace_back
const long long du=1e9+7;
long long f[3001][3001];
long long combi[3001][3001];
long long pw[3001];
long long fact[6001];
long long inv[6001];
long long g[3001][3001];
long long pow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int m,n;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
cin>>m>>n;
pw[0]=1;
for1(i,1,3000)pw[i]=(pw[i-1]*4)%du;
fact[0]=1;
for1(i,1,6000)fact[i]=(fact[i-1]*i)%du;
for1(i,0,6000){
inv[i]=pow(fact[i],du-2,du);
}
combi[0][0]=1;
for1(i,1,3000){
combi[i][0]=1;
for1(j,1,3000){
combi[i][j]=(combi[i-1][j-1]+combi[i-1][j])%du;
}
}
f[0][0]=1;
for1(i,0,m){
for1(j,0,n){
if (!f[i][j])continue;
int t1=j*2+i,t2=i*2+j;
if (t1>m||t2>n){
f[i][j]=0;
continue;
}
if (t1+1<=m&&t2+2<=n){
long long dd=(combi[m-t1][1]*combi[n-t2][2])%du;
f[i+1][j]=(f[i+1][j]+f[i][j]*dd)%du;
}
if (t1+2<=m&&t2+1<=n){
long long dd=(combi[m-t1][2]*combi[n-t2][1])%du;
f[i][j+1]=(f[i][j+1]+f[i][j]*dd)%du;
}
}
}
for1(i,0,m){
for1(j,0,n){
if (!f[i][j])continue;
f[i][j]=(f[i][j]*inv[i+j])%du;
}
}
long long ans=0;
for1(i,0,m){
for1(j,0,n){
if (!f[i][j])continue;
int t1=j*2+i,t2=i*2+j;
int l1=m-t1,l2=n-t2;
/*for1(k,min(l1,l2),min(l1,l2)){
long long dd=(pw[k]*combi[l1][k])%du;
dd=(dd*combi[l2][k])%du;
dd=(dd*fact[k])%du;
ans=(ans+f[i][j]*dd)%du;
}*/
g[t1][t2]=(g[t1][t2]+f[i][j])%du;
}
}
for1(i,0,m){
for1(j,0,n){
if (!g[i][j])continue;
if (i+1<=m){
g[i+1][j]=(g[i+1][j]+g[i][j])%du;
}
if (i+1<=m&&j+1<=n){
g[i+1][j+1]=(g[i+1][j+1]+g[i][j]*4*(n-j))%du;
}
}
}
for1(i,m,m){
for1(j,0,n){
ans=(ans+g[i][j])%du;
}
}
cout<<(ans-1+du)%du;
}
Compilation message (stderr)
tents.cpp: In function 'int main()':
tents.cpp:89:9: warning: unused variable 'l1' [-Wunused-variable]
89 | int l1=m-t1,l2=n-t2;
| ^~
tents.cpp:89:17: warning: unused variable 'l2' [-Wunused-variable]
89 | int l1=m-t1,l2=n-t2;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |