Submission #545856

# Submission time Handle Problem Language Result Execution time Memory
545856 2022-04-05T15:22:04 Z Sohsoh84 Boat (APIO16_boat) C++17
100 / 100
1652 ms 14380 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 = 1000 + 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][MAXN], dp[MAXN][MAXN], 
    ps[MAXN][MAXN], inv[MAXN];
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;
}
# Verdict Execution time Memory Grader output
1 Correct 665 ms 14244 KB Output is correct
2 Correct 677 ms 14112 KB Output is correct
3 Correct 673 ms 14284 KB Output is correct
4 Correct 707 ms 14264 KB Output is correct
5 Correct 674 ms 14196 KB Output is correct
6 Correct 669 ms 14252 KB Output is correct
7 Correct 666 ms 14212 KB Output is correct
8 Correct 675 ms 14220 KB Output is correct
9 Correct 683 ms 14260 KB Output is correct
10 Correct 667 ms 14380 KB Output is correct
11 Correct 673 ms 14316 KB Output is correct
12 Correct 678 ms 14292 KB Output is correct
13 Correct 665 ms 14320 KB Output is correct
14 Correct 677 ms 14284 KB Output is correct
15 Correct 688 ms 14160 KB Output is correct
16 Correct 123 ms 7724 KB Output is correct
17 Correct 135 ms 7816 KB Output is correct
18 Correct 129 ms 7760 KB Output is correct
19 Correct 133 ms 7828 KB Output is correct
20 Correct 130 ms 7756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 665 ms 14244 KB Output is correct
2 Correct 677 ms 14112 KB Output is correct
3 Correct 673 ms 14284 KB Output is correct
4 Correct 707 ms 14264 KB Output is correct
5 Correct 674 ms 14196 KB Output is correct
6 Correct 669 ms 14252 KB Output is correct
7 Correct 666 ms 14212 KB Output is correct
8 Correct 675 ms 14220 KB Output is correct
9 Correct 683 ms 14260 KB Output is correct
10 Correct 667 ms 14380 KB Output is correct
11 Correct 673 ms 14316 KB Output is correct
12 Correct 678 ms 14292 KB Output is correct
13 Correct 665 ms 14320 KB Output is correct
14 Correct 677 ms 14284 KB Output is correct
15 Correct 688 ms 14160 KB Output is correct
16 Correct 123 ms 7724 KB Output is correct
17 Correct 135 ms 7816 KB Output is correct
18 Correct 129 ms 7760 KB Output is correct
19 Correct 133 ms 7828 KB Output is correct
20 Correct 130 ms 7756 KB Output is correct
21 Correct 226 ms 13632 KB Output is correct
22 Correct 233 ms 13516 KB Output is correct
23 Correct 208 ms 13516 KB Output is correct
24 Correct 216 ms 13428 KB Output is correct
25 Correct 215 ms 13448 KB Output is correct
26 Correct 289 ms 13196 KB Output is correct
27 Correct 292 ms 13324 KB Output is correct
28 Correct 279 ms 13240 KB Output is correct
29 Correct 282 ms 13260 KB Output is correct
30 Correct 639 ms 14140 KB Output is correct
31 Correct 656 ms 14188 KB Output is correct
32 Correct 649 ms 14200 KB Output is correct
33 Correct 693 ms 14172 KB Output is correct
34 Correct 676 ms 14196 KB Output is correct
35 Correct 669 ms 14128 KB Output is correct
36 Correct 665 ms 14104 KB Output is correct
37 Correct 700 ms 14284 KB Output is correct
38 Correct 670 ms 14168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6228 KB Output is correct
2 Correct 18 ms 6260 KB Output is correct
3 Correct 18 ms 6324 KB Output is correct
4 Correct 20 ms 6220 KB Output is correct
5 Correct 19 ms 6316 KB Output is correct
6 Correct 20 ms 6256 KB Output is correct
7 Correct 18 ms 6228 KB Output is correct
8 Correct 20 ms 6228 KB Output is correct
9 Correct 20 ms 6288 KB Output is correct
10 Correct 18 ms 6308 KB Output is correct
11 Correct 18 ms 6252 KB Output is correct
12 Correct 19 ms 6268 KB Output is correct
13 Correct 17 ms 6312 KB Output is correct
14 Correct 16 ms 6228 KB Output is correct
15 Correct 17 ms 6228 KB Output is correct
16 Correct 13 ms 5568 KB Output is correct
17 Correct 11 ms 5588 KB Output is correct
18 Correct 12 ms 5568 KB Output is correct
19 Correct 12 ms 5588 KB Output is correct
20 Correct 11 ms 5528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 665 ms 14244 KB Output is correct
2 Correct 677 ms 14112 KB Output is correct
3 Correct 673 ms 14284 KB Output is correct
4 Correct 707 ms 14264 KB Output is correct
5 Correct 674 ms 14196 KB Output is correct
6 Correct 669 ms 14252 KB Output is correct
7 Correct 666 ms 14212 KB Output is correct
8 Correct 675 ms 14220 KB Output is correct
9 Correct 683 ms 14260 KB Output is correct
10 Correct 667 ms 14380 KB Output is correct
11 Correct 673 ms 14316 KB Output is correct
12 Correct 678 ms 14292 KB Output is correct
13 Correct 665 ms 14320 KB Output is correct
14 Correct 677 ms 14284 KB Output is correct
15 Correct 688 ms 14160 KB Output is correct
16 Correct 123 ms 7724 KB Output is correct
17 Correct 135 ms 7816 KB Output is correct
18 Correct 129 ms 7760 KB Output is correct
19 Correct 133 ms 7828 KB Output is correct
20 Correct 130 ms 7756 KB Output is correct
21 Correct 226 ms 13632 KB Output is correct
22 Correct 233 ms 13516 KB Output is correct
23 Correct 208 ms 13516 KB Output is correct
24 Correct 216 ms 13428 KB Output is correct
25 Correct 215 ms 13448 KB Output is correct
26 Correct 289 ms 13196 KB Output is correct
27 Correct 292 ms 13324 KB Output is correct
28 Correct 279 ms 13240 KB Output is correct
29 Correct 282 ms 13260 KB Output is correct
30 Correct 639 ms 14140 KB Output is correct
31 Correct 656 ms 14188 KB Output is correct
32 Correct 649 ms 14200 KB Output is correct
33 Correct 693 ms 14172 KB Output is correct
34 Correct 676 ms 14196 KB Output is correct
35 Correct 669 ms 14128 KB Output is correct
36 Correct 665 ms 14104 KB Output is correct
37 Correct 700 ms 14284 KB Output is correct
38 Correct 670 ms 14168 KB Output is correct
39 Correct 19 ms 6228 KB Output is correct
40 Correct 18 ms 6260 KB Output is correct
41 Correct 18 ms 6324 KB Output is correct
42 Correct 20 ms 6220 KB Output is correct
43 Correct 19 ms 6316 KB Output is correct
44 Correct 20 ms 6256 KB Output is correct
45 Correct 18 ms 6228 KB Output is correct
46 Correct 20 ms 6228 KB Output is correct
47 Correct 20 ms 6288 KB Output is correct
48 Correct 18 ms 6308 KB Output is correct
49 Correct 18 ms 6252 KB Output is correct
50 Correct 19 ms 6268 KB Output is correct
51 Correct 17 ms 6312 KB Output is correct
52 Correct 16 ms 6228 KB Output is correct
53 Correct 17 ms 6228 KB Output is correct
54 Correct 13 ms 5568 KB Output is correct
55 Correct 11 ms 5588 KB Output is correct
56 Correct 12 ms 5568 KB Output is correct
57 Correct 12 ms 5588 KB Output is correct
58 Correct 11 ms 5528 KB Output is correct
59 Correct 1563 ms 14176 KB Output is correct
60 Correct 1507 ms 14192 KB Output is correct
61 Correct 1501 ms 14288 KB Output is correct
62 Correct 1524 ms 14164 KB Output is correct
63 Correct 1508 ms 14164 KB Output is correct
64 Correct 1624 ms 14196 KB Output is correct
65 Correct 1652 ms 14148 KB Output is correct
66 Correct 1605 ms 14216 KB Output is correct
67 Correct 1610 ms 14224 KB Output is correct
68 Correct 1610 ms 14308 KB Output is correct
69 Correct 1470 ms 14156 KB Output is correct
70 Correct 1453 ms 14196 KB Output is correct
71 Correct 1474 ms 14204 KB Output is correct
72 Correct 1463 ms 14304 KB Output is correct
73 Correct 1467 ms 14300 KB Output is correct
74 Correct 181 ms 7660 KB Output is correct
75 Correct 172 ms 7748 KB Output is correct
76 Correct 180 ms 7776 KB Output is correct
77 Correct 178 ms 7876 KB Output is correct
78 Correct 182 ms 7640 KB Output is correct