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 <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9, mod = 1e9+7, inv2 = (mod+1)/2;
void solve(){
int n, m;
cin >> n >> m;
vector<vector<ll>> f(n+1, vector<ll>(m+1, 0)); // consider problem FILL (not rectangle) from (1, 1) to (i, j)
for(int i = 1; i <= n; i++) f[i][0] = 1;
for(int j = 0; j <= m; j++) f[0][j] = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
//nothing on ith row
f[i][j] += f[i-1][j];
//place one thing on ith row
f[i][j] += f[i-1][j-1] * (j*4)%mod;
//place 2 horizontally
if(j-2 >= 0) f[i][j] += f[i-1][j-2] * (j*(j-1)%mod*inv2%mod)%mod;
//place 2 vertically
if(i-2 >= 0) f[i][j] += f[i-2][j-1] * (j*(i-1)%mod)%mod;
f[i][j] %= mod;
}
}
cout << f[n][m]-1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |