Submission #255089

# Submission time Handle Problem Language Result Execution time Memory
255089 2020-07-31T09:07:52 Z maximath_1 Boat (APIO16_boat) C++11
100 / 100
469 ms 4472 KB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;

int n;
int st[1005], ed[1005], len[1005];
int inv[1005], dp[1005][1005];
vector<int> cc;

int add(int a, int b){
	int res = a + b;
	if(res >= mod) res -= mod;
	return res;
}

int mul(int a, int b){
	return (a * 1ll * b) % mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> st[i] >> ed[i];
		ed[i] ++;
	}

	inv[1] = 1;
	for(int i = 2; i <= n; i ++)
		inv[i] = mul(mod / i, mod - inv[mod % i]);

	for(int i = 1; i <= n; i ++){
		cc.push_back(st[i]);cc.push_back(ed[i]);
	}
	sort(cc.begin(), cc.end());
	cc.erase(unique(cc.begin(), cc.end()), cc.end());

	for(int i = 1; i <= n; i ++){
		st[i] = upper_bound(cc.begin(), cc.end(), st[i]) - cc.begin();
		ed[i] = upper_bound(cc.begin(), cc.end(), ed[i]) - cc.begin();
	}

	int sz = cc.size() - 1;
	for(int i = 1; i <= sz; i ++)
		len[i] = cc[i] - cc[i - 1];

	dp[0][0] = 1;
	for(int i = 1; i <= sz; i ++){
		dp[i][0] = 1;
		for(int j = 1; j <= n; j ++){
			int choose = len[i]; int cnt = 1;
			dp[i][j] = dp[i - 1][j];
			if(i < st[j] || i >= ed[j]) continue;

			for(int k = j - 1; k >= 0; k --){
				dp[i][j] = add(dp[i][j], mul(dp[i - 1][k], choose));
				if(st[k] <= i && i < ed[k]){
					choose = mul(choose, mul(add(cnt, len[i]), inv[cnt + 1]));
					cnt ++;
				}
			}
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i ++)
		ans = add(ans, dp[sz][i]);
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4224 KB Output is correct
2 Correct 4 ms 4224 KB Output is correct
3 Correct 4 ms 4224 KB Output is correct
4 Correct 4 ms 4224 KB Output is correct
5 Correct 4 ms 4224 KB Output is correct
6 Correct 3 ms 4224 KB Output is correct
7 Correct 3 ms 4224 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 4 ms 4224 KB Output is correct
10 Correct 3 ms 4352 KB Output is correct
11 Correct 4 ms 4352 KB Output is correct
12 Correct 4 ms 4224 KB Output is correct
13 Correct 4 ms 4224 KB Output is correct
14 Correct 4 ms 4224 KB Output is correct
15 Correct 4 ms 4224 KB Output is correct
16 Correct 2 ms 1024 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 1024 KB Output is correct
19 Correct 2 ms 1152 KB Output is correct
20 Correct 2 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4224 KB Output is correct
2 Correct 4 ms 4224 KB Output is correct
3 Correct 4 ms 4224 KB Output is correct
4 Correct 4 ms 4224 KB Output is correct
5 Correct 4 ms 4224 KB Output is correct
6 Correct 3 ms 4224 KB Output is correct
7 Correct 3 ms 4224 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 4 ms 4224 KB Output is correct
10 Correct 3 ms 4352 KB Output is correct
11 Correct 4 ms 4352 KB Output is correct
12 Correct 4 ms 4224 KB Output is correct
13 Correct 4 ms 4224 KB Output is correct
14 Correct 4 ms 4224 KB Output is correct
15 Correct 4 ms 4224 KB Output is correct
16 Correct 2 ms 1024 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 1024 KB Output is correct
19 Correct 2 ms 1152 KB Output is correct
20 Correct 2 ms 1024 KB Output is correct
21 Correct 251 ms 3960 KB Output is correct
22 Correct 247 ms 3964 KB Output is correct
23 Correct 227 ms 3960 KB Output is correct
24 Correct 250 ms 3896 KB Output is correct
25 Correct 243 ms 3960 KB Output is correct
26 Correct 407 ms 3832 KB Output is correct
27 Correct 414 ms 3832 KB Output is correct
28 Correct 404 ms 3832 KB Output is correct
29 Correct 404 ms 3960 KB Output is correct
30 Correct 5 ms 4224 KB Output is correct
31 Correct 4 ms 4224 KB Output is correct
32 Correct 4 ms 4224 KB Output is correct
33 Correct 5 ms 4224 KB Output is correct
34 Correct 4 ms 4224 KB Output is correct
35 Correct 5 ms 4276 KB Output is correct
36 Correct 6 ms 4224 KB Output is correct
37 Correct 5 ms 4224 KB Output is correct
38 Correct 5 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 2 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 2 ms 768 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4224 KB Output is correct
2 Correct 4 ms 4224 KB Output is correct
3 Correct 4 ms 4224 KB Output is correct
4 Correct 4 ms 4224 KB Output is correct
5 Correct 4 ms 4224 KB Output is correct
6 Correct 3 ms 4224 KB Output is correct
7 Correct 3 ms 4224 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 4 ms 4224 KB Output is correct
10 Correct 3 ms 4352 KB Output is correct
11 Correct 4 ms 4352 KB Output is correct
12 Correct 4 ms 4224 KB Output is correct
13 Correct 4 ms 4224 KB Output is correct
14 Correct 4 ms 4224 KB Output is correct
15 Correct 4 ms 4224 KB Output is correct
16 Correct 2 ms 1024 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 1024 KB Output is correct
19 Correct 2 ms 1152 KB Output is correct
20 Correct 2 ms 1024 KB Output is correct
21 Correct 251 ms 3960 KB Output is correct
22 Correct 247 ms 3964 KB Output is correct
23 Correct 227 ms 3960 KB Output is correct
24 Correct 250 ms 3896 KB Output is correct
25 Correct 243 ms 3960 KB Output is correct
26 Correct 407 ms 3832 KB Output is correct
27 Correct 414 ms 3832 KB Output is correct
28 Correct 404 ms 3832 KB Output is correct
29 Correct 404 ms 3960 KB Output is correct
30 Correct 5 ms 4224 KB Output is correct
31 Correct 4 ms 4224 KB Output is correct
32 Correct 4 ms 4224 KB Output is correct
33 Correct 5 ms 4224 KB Output is correct
34 Correct 4 ms 4224 KB Output is correct
35 Correct 5 ms 4276 KB Output is correct
36 Correct 6 ms 4224 KB Output is correct
37 Correct 5 ms 4224 KB Output is correct
38 Correct 5 ms 4224 KB Output is correct
39 Correct 3 ms 1152 KB Output is correct
40 Correct 3 ms 1152 KB Output is correct
41 Correct 3 ms 1152 KB Output is correct
42 Correct 3 ms 1152 KB Output is correct
43 Correct 3 ms 1152 KB Output is correct
44 Correct 4 ms 1152 KB Output is correct
45 Correct 5 ms 1152 KB Output is correct
46 Correct 6 ms 1152 KB Output is correct
47 Correct 5 ms 1152 KB Output is correct
48 Correct 5 ms 1152 KB Output is correct
49 Correct 4 ms 1152 KB Output is correct
50 Correct 2 ms 1152 KB Output is correct
51 Correct 3 ms 1152 KB Output is correct
52 Correct 3 ms 1152 KB Output is correct
53 Correct 3 ms 1152 KB Output is correct
54 Correct 2 ms 768 KB Output is correct
55 Correct 2 ms 768 KB Output is correct
56 Correct 2 ms 768 KB Output is correct
57 Correct 2 ms 768 KB Output is correct
58 Correct 2 ms 768 KB Output is correct
59 Correct 279 ms 4216 KB Output is correct
60 Correct 273 ms 4344 KB Output is correct
61 Correct 285 ms 4344 KB Output is correct
62 Correct 274 ms 4216 KB Output is correct
63 Correct 284 ms 4216 KB Output is correct
64 Correct 466 ms 4472 KB Output is correct
65 Correct 469 ms 4376 KB Output is correct
66 Correct 467 ms 4344 KB Output is correct
67 Correct 469 ms 4216 KB Output is correct
68 Correct 466 ms 4216 KB Output is correct
69 Correct 218 ms 4216 KB Output is correct
70 Correct 222 ms 4472 KB Output is correct
71 Correct 224 ms 4344 KB Output is correct
72 Correct 227 ms 4216 KB Output is correct
73 Correct 231 ms 4216 KB Output is correct
74 Correct 55 ms 1144 KB Output is correct
75 Correct 52 ms 1144 KB Output is correct
76 Correct 54 ms 1016 KB Output is correct
77 Correct 56 ms 1016 KB Output is correct
78 Correct 55 ms 1016 KB Output is correct