답안 #524571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524571 2022-02-09T14:40:32 Z sare 유적 3 (JOI20_ruins3) C++17
58 / 100
4 ms 3360 KB
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int MAXN = 610, MOD = 1e9 + 7;
int dp[MAXN], pre[MAXN][MAXN], comb[MAXN][MAXN];
bool rem[2 * MAXN];

inline int power (ll a, ll b) {
	ll res = 1;
	for (; b; b >>= 1, a = (a * a) % MOD) {
		if (b & 1) {
			res = (res * a) % MOD;
		}
	}
	return res;
}
inline int inv (int x) {
	return power(x, MOD - 2);
}

inline void add (int& a, const int& b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int main() {
	ios::sync_with_stdio(0);
#ifndef LOCAL
	cin.tie(0);
#endif
	for (int i = 0; i < MAXN; i++) {
		comb[i][i] = comb[i][0] = 1;
		for (int j = 1; j < i; j++) {
			comb[i][j] = comb[i - 1][j];
			add(comb[i][j], comb[i - 1][j - 1]);
		}
	}

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		rem[x] = 1;
	}

	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			add(dp[i], 1ll * comb[i - 1][j - 1] * dp[j - 1] % MOD * dp[i - j] % MOD * (i - j + 2) % MOD);
		}
	}
	
	int c0 = 0, c1 = 0;
	pre[n + n + 1][0] = 1;
	for (int k = n + n; k; k--) {
		if (rem[k]) {
			memcpy(pre[k], pre[k + 1], sizeof(pre[k]));
			for (int i = 0; i <= c1 + 1; i++) {
				for (int j = 1; j <= i; j++) {
					add(pre[k][i], 1ll * comb[c1 - j + 1][i - j] * pre[k + 1][j - 1] % MOD * dp[i - j] % MOD * (i - j + 2) % MOD);
				}
			}
			c1++;
		}
		else {
			for (int i = 0; i <= c1; i++) {
				pre[k][i] = 1ll * pre[k + 1][i] * max(0, i - c0) % MOD;
			}
			c0++;
		}
	}
	int ans = 1ll * pre[1][n] * inv(power(2, n)) % MOD;
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 1 ms 1776 KB Output is correct
4 Correct 1 ms 1760 KB Output is correct
5 Correct 1 ms 1740 KB Output is correct
6 Correct 1 ms 1740 KB Output is correct
7 Correct 1 ms 1776 KB Output is correct
8 Correct 1 ms 1784 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 1 ms 1780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 1 ms 1776 KB Output is correct
4 Correct 1 ms 1760 KB Output is correct
5 Correct 1 ms 1740 KB Output is correct
6 Correct 1 ms 1740 KB Output is correct
7 Correct 1 ms 1776 KB Output is correct
8 Correct 1 ms 1784 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 1 ms 1780 KB Output is correct
11 Correct 2 ms 1996 KB Output is correct
12 Correct 2 ms 2124 KB Output is correct
13 Correct 3 ms 2024 KB Output is correct
14 Correct 2 ms 2012 KB Output is correct
15 Correct 2 ms 2024 KB Output is correct
16 Correct 2 ms 2032 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1988 KB Output is correct
19 Correct 2 ms 1996 KB Output is correct
20 Correct 3 ms 1996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 1 ms 1776 KB Output is correct
4 Correct 1 ms 1760 KB Output is correct
5 Correct 1 ms 1740 KB Output is correct
6 Correct 1 ms 1740 KB Output is correct
7 Correct 1 ms 1776 KB Output is correct
8 Correct 1 ms 1784 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 1 ms 1780 KB Output is correct
11 Correct 2 ms 1996 KB Output is correct
12 Correct 2 ms 2124 KB Output is correct
13 Correct 3 ms 2024 KB Output is correct
14 Correct 2 ms 2012 KB Output is correct
15 Correct 2 ms 2024 KB Output is correct
16 Correct 2 ms 2032 KB Output is correct
17 Correct 2 ms 2028 KB Output is correct
18 Correct 2 ms 1988 KB Output is correct
19 Correct 2 ms 1996 KB Output is correct
20 Correct 3 ms 1996 KB Output is correct
21 Runtime error 4 ms 3360 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -