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>
#define ll long long
#define mod 998244353
#define rep(i,s) for(ll i=0; i<s ; i++)
#define f(i,a,b) for(long long i(a); i<b ; i++)
#define inf -pow(10,9)
#define MAXN 100000
const ll INF = 1000000000;
const ll N = 50005;
const ll modi = 1000000007;
const ll modi2= 1000000006;
using namespace std;
int main(){
ll h,w;
cin >> h >> w;
ll dp[h+1][w+1];
rep(i,h+1){
rep(j,w+1){
dp[i][j]=0;
}
}
rep(i,h+1){
dp[i][0]=1;
}
rep(i,w+1){
dp[0][i]=1;
}
f(i,1,h+1){
f(j,1,w+1){
dp[i][j]=(dp[i][j]+dp[i][j-1]+modi)%modi;
dp[i][j]=(dp[i][j]+4*i*dp[i-1][j-1] + modi)%modi;
ll val1=(i*(i-1))/2;
ll val2=(i*(j-1));
if(i>1){
ll x1=(val1*dp[i-2][j-1]+modi)%modi;
dp[i][j]=(dp[i][j]+x1+modi)%modi;
}
if(j>1){
ll x2=(val2*dp[i-1][j-2]+modi)%modi;
dp[i][j]=(dp[i][j]+x2+modi)%modi;
}
// cout << i << " " << j << " " << dp[i][j] << endl;
}
}
cout << dp[h][w]-1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |