# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101112 | TgX_2 | Tents (JOI18_tents) | C++17 | 78 ms | 71252 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*-----------------------------
Author : TgX.2
11Ti - K28 - CHV
-----------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i += 1)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i -= 1)
#define fi first
#define se second
#define len(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define _ << " " <<
#define __ << "\n"
#define ___ << " "
#define ______________TgX______________ main()
#define int long long
#define intmax 1e9
#define intmin -1e9
#define llongmax 1e18
#define llongmin -1e18
#define memo(a, val) memset((a), (val), sizeof((a)))
struct custom {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<class T1, class T2> using cmap = unordered_map<T1, T2, custom>;
template<typename T1, typename T2>
bool mini(T1 &a, T2 b)
{if (a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2>
bool maxi(T1 &a, T2 b)
{if (a < b) a = b; else return 0; return 1;}
/*-----------------------------*/
const int maxn = 3007;
const int mod = 1e9 + 7;
int n, m;
int f[maxn][maxn];
int dp(int i, int j) {
if (i < 0 or j < 0) return 0;
if (i == 0 or j == 0) return 1;
int &ans = f[i][j];
if (ans != -1) return ans;
ans = 0;
(ans += dp(i, j - 1)) % mod;
(ans += ((4 * i) % mod * dp(i - 1, j - 1)) % mod) % mod;
(ans += (i * (i - 1) / 2 % mod * dp(i - 2, j - 1)) % mod) % mod;
(ans += ((i * (j - 1)) % mod * dp(i - 1, j - 2)) % mod) % mod;
return ans;
}
void process() {
cin >> n >> m;
memo(f, -1);
cout << (dp(n, m) - 1 + mod) % mod;
}
/*-----------------------------*/
______________TgX______________ {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("temp.inp", "r")) {
freopen("temp.inp", "r", stdin);
freopen("temp.out", "w", stdout);
}
process();
cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." __ ;
}
/*==============================+
|INPUT |
--------------------------------|
================================+
|OUTPUT |
--------------------------------|
===============================*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |