Submission #525610

# Submission time Handle Problem Language Result Execution time Memory
525610 2022-02-12T06:41:05 Z ParsaEs Ruins 3 (JOI20_ruins3) C++17
100 / 100
390 ms 18716 KB
//InTheNameOfGOD
//PRS;)
#include<iostream>
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int xn = 2e3 + 5;
ll cnt[xn][xn], pr[xn][xn], dp[xn];
bool vis[xn << 1];
ll pp(ll x, ll y)
{
	if(y < 1) return 1;
	if(y < 2) return x;
	ll ret = pp(x, y / 2);
	ret = (ret * ret) % mod;
	if(y & 1) ret = (ret * x) % mod;
	return ret;
}
int main()
{
	Fast
	int n;
	cin >> n;
	for(int i = 0; i <= n; i++) cnt[0][i] = 1;
	for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++)
		cnt[i][j] = (cnt[i - 1][j - 1] + cnt[i][j - 1]) % mod;
	pr[n * 2 + 1][0] = dp[0] = 1;
	for(ll i = 1; i <= n; i++) for(ll j = 1; j <= i; j++)
	{
		ll prs = (cnt[j - 1][i - 1] * dp[j - 1]) % mod;
		prs = (prs * dp[i - j]) % mod;
		prs = (prs * (i - j + 2)) % mod;
		dp[i] = (dp[i] + prs) % mod;
	}
	int n1 = n;
	while(n1--)
	{
		int x;
		cin >> x;
		vis[x] = 1;
	}
	ll a1 = 0, a2 = 0;
	for(int i = (n << 1); i > 0; i--)
	{
		if(!vis[i])
		{
			ll z = 0;
			for(int j = 0; j <= a2; j++) pr[i][j] = (pr[i + 1][j] * max(j - a1, z)) % mod;
			a1++;
			continue;
		}
		for(int j = 0; j < xn; j++) pr[i][j] = pr[i + 1][j];
		for(int j = 0; j <= a2 + 1; j++) for(int k = 1; k <= j; k++)
		{
			ll prs = (cnt[j - k][a2 - k + 1] * pr[i + 1][k - 1]) % mod;
			prs = (prs * dp[j - k]) % mod;
			prs = (prs * (j - k + 2)) % mod;
			pr[i][j] = (pr[i][j] + prs) % mod;
		}
		a2++;
	}
	ll ans = pp(pp(2, n), mod - 2);
	ans = (ans * pr[1][n]) % mod;
	return cout << ans << '\n', 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 576 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 576 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 1740 KB Output is correct
12 Correct 1 ms 1740 KB Output is correct
13 Correct 1 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1692 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 2 ms 1740 KB Output is correct
20 Correct 2 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 576 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 1740 KB Output is correct
12 Correct 1 ms 1740 KB Output is correct
13 Correct 1 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1692 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 2 ms 1740 KB Output is correct
20 Correct 2 ms 1740 KB Output is correct
21 Correct 371 ms 17504 KB Output is correct
22 Correct 350 ms 17396 KB Output is correct
23 Correct 360 ms 17408 KB Output is correct
24 Correct 356 ms 17488 KB Output is correct
25 Correct 375 ms 17348 KB Output is correct
26 Correct 350 ms 17324 KB Output is correct
27 Correct 351 ms 17344 KB Output is correct
28 Correct 352 ms 17348 KB Output is correct
29 Correct 348 ms 15956 KB Output is correct
30 Correct 357 ms 18704 KB Output is correct
31 Correct 373 ms 18468 KB Output is correct
32 Correct 357 ms 18616 KB Output is correct
33 Correct 362 ms 18716 KB Output is correct
34 Correct 356 ms 18600 KB Output is correct
35 Correct 362 ms 18524 KB Output is correct
36 Correct 390 ms 18668 KB Output is correct