Submission #1154503

#TimeUsernameProblemLanguageResultExecution timeMemory
1154503NurislamTents (JOI18_tents)C++20
100 / 100
86 ms70984 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)

const int inf = 1e6, mod = 1e9 + 7;

void solve(){
	
	auto add = [&](int &a, int b) -> void{
		a = (a + b) %mod;
		if(a < 0) a += mod;
	};
	
	int h, w; cin >> h >> w;
    vector <vector<int>> dp(h + 1, vector <int> (w + 1));
    for ( int i = 0; i <= h; i++ ){
        for ( int j = 0; j <= w; j++ ){
            if ( !i || !j ){
                dp[i][j] = 1;
                continue;
            }
            add(dp[i][j], dp[i - 1][j - 1] * 4 * j + dp[i - 1][j]);
            if ( i >= 2 ){
                add(dp[i][j], dp[i - 2][j - 1] * (i - 1) * j);
            }
            if ( j >= 2 ){
                add(dp[i][j], dp[i - 1][j - 2] * (j * (j - 1) / 2));
            }
        }
    }
    add(dp[h][w], -1);
    cout << dp[h][w] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    };
}














#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...