Submission #94079

# Submission time Handle Problem Language Result Execution time Memory
94079 2019-01-15T16:31:01 Z aminra Tents (JOI18_tents) C++14
100 / 100
1320 ms 117396 KB
//tavakol bar khoda
/*
	1. pish miad
	2. pish miad
	3. pish miad
	4. base dg? :(
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)3007;
const int infint = (int)1e8 + 3;
const int MOD = (int)1e9 + 7;
const ll inf = (ll)1e18;
ll H, W, dp[MAXN][MAXN], C[MAXN][MAXN], fact[MAXN];
ll pwr(ll a, ll b)
{
	if(b == 0)	
		return 1;
	if(b == 1)
		return a;
	ll c = pwr(a, b / 2);
	c = (c * c) % MOD;
	if(b % 2)
		c = (c * a) % MOD;
	return c;
}
ll inv(ll a)
{
	return pwr(a, MOD - 2);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> H >> W;
	//-----------------------------------
	for (int i = 0; i <= W; i++)
		dp[1][i] = i * 4 % MOD + 1, dp[0][i] = 1;
	dp[1][0] = 1;
	
	for (int i = 2; i <= H; i++)
		for (int j = 0; j <= W; j++)
		{
			dp[i][j] = dp[i - 1][j];
			if(j)
				dp[i][j] = dp[i][j] + j * 4 % MOD * dp[i - 1][j - 1] % MOD, dp[i][j] %= MOD;
		}
	//------------------------------------
	fact[0] = 1;
	for (int i = 1; i < MAXN; i++)
		fact[i] = fact[i - 1] * i % MOD;
	C[0][0] = 1;
	for (int i = 1; i < MAXN; i++)
		for (int j = 0; j <= i; j++)
			if(j == 0 || j == i)
				C[i][j] = 1;
			else
				C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
	//-------------------------------------	
	ll ans = 0;
	for (int i = 0; i <= H; i++)
		for (int j = 0; 2 * i + j <= H && i + 2 * j <= W; j++)
		{
			ll nwH = H - 2 * i - j, nwW = W - i - 2 * j;
			ans += C[W][i] * C[H][2 * i] % MOD * fact[2 * i] % MOD * inv(pwr(2, i)) % MOD * C[H - 2 * i][j] % MOD * C[W - i][2 * j] % MOD * fact[2 * j] % MOD * inv(pwr(2, j)) % MOD * dp[nwH][nwW] % MOD,
			ans %= MOD;
		}
	cout << (ans - 1 + MOD) % MOD;
}
# Verdict Execution time Memory Grader output
1 Correct 45 ms 46712 KB Output is correct
2 Correct 39 ms 46712 KB Output is correct
3 Correct 37 ms 46840 KB Output is correct
4 Correct 43 ms 47608 KB Output is correct
5 Correct 38 ms 47100 KB Output is correct
6 Correct 45 ms 47736 KB Output is correct
7 Correct 46 ms 47224 KB Output is correct
8 Correct 46 ms 47864 KB Output is correct
9 Correct 43 ms 47224 KB Output is correct
10 Correct 47 ms 48120 KB Output is correct
11 Correct 45 ms 46828 KB Output is correct
12 Correct 54 ms 48632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 46712 KB Output is correct
2 Correct 39 ms 46712 KB Output is correct
3 Correct 37 ms 46840 KB Output is correct
4 Correct 43 ms 47608 KB Output is correct
5 Correct 38 ms 47100 KB Output is correct
6 Correct 45 ms 47736 KB Output is correct
7 Correct 46 ms 47224 KB Output is correct
8 Correct 46 ms 47864 KB Output is correct
9 Correct 43 ms 47224 KB Output is correct
10 Correct 47 ms 48120 KB Output is correct
11 Correct 45 ms 46828 KB Output is correct
12 Correct 54 ms 48632 KB Output is correct
13 Correct 38 ms 46712 KB Output is correct
14 Correct 51 ms 56052 KB Output is correct
15 Correct 680 ms 101636 KB Output is correct
16 Correct 59 ms 50424 KB Output is correct
17 Correct 136 ms 59320 KB Output is correct
18 Correct 232 ms 63480 KB Output is correct
19 Correct 835 ms 109432 KB Output is correct
20 Correct 683 ms 97400 KB Output is correct
21 Correct 458 ms 80248 KB Output is correct
22 Correct 463 ms 81868 KB Output is correct
23 Correct 302 ms 73464 KB Output is correct
24 Correct 1320 ms 117396 KB Output is correct
25 Correct 837 ms 107768 KB Output is correct
26 Correct 985 ms 113140 KB Output is correct
27 Correct 1172 ms 115580 KB Output is correct