답안 #545853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545853 2022-04-05T15:19:25 Z Sohsoh84 Boat (APIO16_boat) C++17
27 / 100
727 ms 7228 KB
#include <bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 500 + 10;
const ll MOD = 1e9 + 7;

void mkey(int& a) {
	if (a >= MOD) a -= MOD;
}

inline ll poww(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % MOD;
		b >>= 1;
		a = a * a % MOD;
	}

	return ans;
}

int n, L[MAXN], R[MAXN], C[MAXN][MAXN], PC[MAXN << 1][MAXN], dp[MAXN][MAXN << 1], 
    ps[MAXN << 1][MAXN], inv[MAXN << 1];
vector<int> vec;

inline int ind(int x) {
	return lower_bound(all(vec), x) - vec.begin();
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);	
	C[0][0] = 1;
	for (int i = 1; i < MAXN; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
			mkey(C[i][j] = C[i - 1][j - 1] + C[i - 1][j]);
	}

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> L[i] >> R[i];
		vec.push_back(L[i] - 1);
		vec.push_back(R[i]);
		inv[i] = poww(i, MOD - 2);
	}

	vec.push_back(-1);
	sort(all(vec));
	vec.resize(unique(all(vec)) - vec.begin());

	for (int j = 1; j < int(vec.size()); j++) {
		for (int i = 1; i <= n; i++) {
			ps[j][i] = ps[j][i - 1] + (vec[j - 1] + 1 >= L[i] && vec[j] <= R[i]);
		}

		int sz = vec[j] - vec[j - 1];
		for (int k = 1; k <= n; k++) {	
			ll f = 1;
			for (int i = 1; i <= min(sz, k); i++) {
				f = f * (sz - i + 1) % MOD * inv[i] % MOD;
				mkey(PC[j][k] += f * C[k - 1][i - 1] % MOD);
			}
		}
	}


	fill(dp[0], dp[0] + MAXN, 1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int l = ind(L[i] - 1), r = ind(R[i]);
		for (int j = 1; j < int(vec.size()); j++) {
			dp[i][j] = dp[i][j - 1];
			
			if (j > l && j <= r) {
				for (int k = 0; k < i; k++) {
					dp[i][j] = (dp[i][j] + 1ll * PC[j][ps[j][i] - ps[j][k]] * dp[k][j - 1]) % MOD;	
				}
			}
		}

		mkey(ans += dp[i][int(vec.size()) - 1]);
	}

	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 727 ms 7228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 727 ms 7228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2516 KB Output is correct
2 Correct 15 ms 2540 KB Output is correct
3 Correct 16 ms 2572 KB Output is correct
4 Correct 17 ms 2544 KB Output is correct
5 Correct 16 ms 2540 KB Output is correct
6 Correct 16 ms 2516 KB Output is correct
7 Correct 16 ms 2516 KB Output is correct
8 Correct 17 ms 2504 KB Output is correct
9 Correct 17 ms 2488 KB Output is correct
10 Correct 19 ms 2532 KB Output is correct
11 Correct 15 ms 2516 KB Output is correct
12 Correct 14 ms 2556 KB Output is correct
13 Correct 15 ms 2500 KB Output is correct
14 Correct 14 ms 2508 KB Output is correct
15 Correct 14 ms 2516 KB Output is correct
16 Correct 9 ms 2132 KB Output is correct
17 Correct 8 ms 2148 KB Output is correct
18 Correct 8 ms 2132 KB Output is correct
19 Correct 8 ms 2132 KB Output is correct
20 Correct 8 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 727 ms 7228 KB Output isn't correct
2 Halted 0 ms 0 KB -