답안 #526609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526609 2022-02-15T14:59:55 Z Arnch 유적 3 (JOI20_ruins3) C++17
100 / 100
556 ms 9344 KB
// oooo
/*
 be hengam shena mesle y dasto pa cholofti ~
 bepa to masire dahane koose neyofti ~
 ;Amoo_Hasan;
*/

#include<bits/stdc++.h>
#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()

const ll inf = 1e18, N = 2000, mod = 1e9 + 7, pr = 1000696969;

int a[N];
ll dp[N], sf[N][N];
ll fac[N], rfac[N];
bool mark[N];

ll poww(ll x, ll y) {
	ll res = 1;
	for(; y; y /= 2, x = x * x % mod)
		if(y & 1) {
			res = res * x % mod;
		}
	return res;
}

void pre() {
	fac[0] = 1;
	for(int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;
	for(int i = 0; i < N; i++) rfac[i] = poww(fac[i], mod - 2);
}

ll choose(ll x, ll y) {
	if(x > y) return 0;
	if(x == y) return 1;
	ll ans = fac[y];
	ans *= rfac[x];
	ans %= mod;
	ans *= rfac[y - x];
	ans %= mod;
	return ans;
}

int main() {
    ios :: sync_with_stdio(0), cin.tie(0);

	pre();
	
	int n; cin >>n;
	for(int i = 1; i <= n; i++) cin >>a[i], mark[a[i]] = 1;
	
	dp[0] = 1;
	for(int len = 1; len <= n; len++) {
		for(int j = 0; j < len; j++) {
			ll val = dp[j] * dp[len - j - 1];
			val %= mod;
			val *= choose(j, len - 1);
			val %= mod;
			val *= j + 2; val %= mod;
			dp[len] += val;
			dp[len] %= mod;
		}
	}

	int c0 = 0, c1 = 0;
	
	
	sf[2 * n + 1][0] = 1;
	for(int i = 2 * n; i > 0; i--) {
		if(mark[i] == 0) {
			for(int R = 0; R <= c1; R++) {
				sf[i][R] = sf[i + 1][R] * (max(0, R - c0));	
				sf[i][R] %= mod;
			}
			c0++;
			continue;
		}
		for(int R = 0; R <= c1 + 1; R++) {
			int k = c1 - R + 1;
			sf[i][R] = sf[i + 1][R];
			sf[i][R] %= mod;
			for(int j = 0; j < R; j++) {
				ll val = dp[j] * sf[i + 1][R - j - 1];
				val %= mod;
				val *= choose(j, c1 - (R - j) + 1);
				val %= mod;
				val *= j + 2;
				val %= mod;
				sf[i][R] += val;
				sf[i][R] %= mod;
			}
		}
		c1++;
	}
	
	ll ans = sf[1][n];
	ans *= poww(poww(2, n), mod - 2);
	ans %= mod;

	cout<<ans;

	
    return 0;
}


Compilation message

ruins3.cpp: In function 'int main()':
ruins3.cpp:88:8: warning: unused variable 'k' [-Wunused-variable]
   88 |    int k = c1 - R + 1;
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 784 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 2 ms 844 KB Output is correct
16 Correct 2 ms 844 KB Output is correct
17 Correct 2 ms 844 KB Output is correct
18 Correct 1 ms 844 KB Output is correct
19 Correct 2 ms 844 KB Output is correct
20 Correct 1 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 784 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 2 ms 844 KB Output is correct
16 Correct 2 ms 844 KB Output is correct
17 Correct 2 ms 844 KB Output is correct
18 Correct 1 ms 844 KB Output is correct
19 Correct 2 ms 844 KB Output is correct
20 Correct 1 ms 844 KB Output is correct
21 Correct 486 ms 8064 KB Output is correct
22 Correct 556 ms 7936 KB Output is correct
23 Correct 547 ms 8024 KB Output is correct
24 Correct 471 ms 8032 KB Output is correct
25 Correct 482 ms 7884 KB Output is correct
26 Correct 471 ms 8000 KB Output is correct
27 Correct 485 ms 7928 KB Output is correct
28 Correct 501 ms 7868 KB Output is correct
29 Correct 479 ms 6468 KB Output is correct
30 Correct 507 ms 9344 KB Output is correct
31 Correct 476 ms 9004 KB Output is correct
32 Correct 465 ms 9172 KB Output is correct
33 Correct 512 ms 9312 KB Output is correct
34 Correct 487 ms 8992 KB Output is correct
35 Correct 468 ms 9100 KB Output is correct
36 Correct 501 ms 9256 KB Output is correct