Submission #47504

# Submission time Handle Problem Language Result Execution time Memory
47504 2018-05-03T23:10:34 Z jun6873 Boat (APIO16_boat) C++11
100 / 100
1548 ms 5616 KB
#include <bits/stdc++.h>
using namespace std;

int n, a[504], b[504], cn, mi[504], c[1004], num[1004], m[1004][504], s0[1004], s[1004][504];

const int mod = 1000000007;
int sum(int x, int y) { return (x+y) % mod; }
int mul(int x, int y) { return (x*(long long)y) % mod; }
int power(int x, int k) {
	if (!k) return 1;
	if (k&1) return mul(x, power(x, k-1));
	int r = power(x, k/2); return mul(r, r);
}

int main() {
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i] >> b[i];
	for (int i=0; i<n; i++) c[2*i] = a[i], c[2*i+1] = b[i]+1;

	sort(c, c+2*n+1);
	cn = unique(c, c+2*n+1) - c;
	for (int i=0; i<n; i++) {
		a[i] = lower_bound(c, c+cn, a[i]) - c;
		b[i] = lower_bound(c, c+cn, b[i]+1) - c;
	}

	for (int i=1; i<504; i++) mi[i] = power(i, mod-2);

	s0[0] = 1;
	s[0][1] = 1; num[0] = 1;
	int ans = 0;
	for (int i=0; i<n; i++) {
		memset(m, 0, sizeof(m));
		for (int j=a[i]; j<b[i]; j++) num[j]++;
		for (int j=a[i]; j<b[i]; j++) for (int jb=0; jb<j; jb++) m[j][1] = sum(m[j][1], mul(c[j+1]-c[j], s0[jb]));
		for (int j=a[i]; j<b[i]; j++) for (int k=2; k<=num[j]; k++) m[j][k] = mul(mul(max(0, c[j+1]-c[j]-k+1), mi[k]), s[j][k-1]);

		for (int j=a[i]; j<b[i]; j++) for (int k=1; k<=num[j]; k++) ans = sum(ans, m[j][k]);
		for (int j=0; j<cn; j++) for (int k=1; k<=num[j]; k++) s0[j] = sum(s0[j], m[j][k]);
		for (int j=0; j<cn; j++) for (int k=1; k<=num[j]; k++) s[j][k] = sum(s[j][k], m[j][k]);
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4344 KB Output is correct
2 Correct 60 ms 4400 KB Output is correct
3 Correct 60 ms 4416 KB Output is correct
4 Correct 62 ms 4488 KB Output is correct
5 Correct 59 ms 4548 KB Output is correct
6 Correct 59 ms 4560 KB Output is correct
7 Correct 62 ms 4680 KB Output is correct
8 Correct 64 ms 4820 KB Output is correct
9 Correct 62 ms 4820 KB Output is correct
10 Correct 64 ms 4840 KB Output is correct
11 Correct 61 ms 4840 KB Output is correct
12 Correct 59 ms 4840 KB Output is correct
13 Correct 59 ms 4840 KB Output is correct
14 Correct 63 ms 4840 KB Output is correct
15 Correct 59 ms 4844 KB Output is correct
16 Correct 54 ms 4844 KB Output is correct
17 Correct 55 ms 4844 KB Output is correct
18 Correct 55 ms 4844 KB Output is correct
19 Correct 56 ms 4844 KB Output is correct
20 Correct 55 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4344 KB Output is correct
2 Correct 60 ms 4400 KB Output is correct
3 Correct 60 ms 4416 KB Output is correct
4 Correct 62 ms 4488 KB Output is correct
5 Correct 59 ms 4548 KB Output is correct
6 Correct 59 ms 4560 KB Output is correct
7 Correct 62 ms 4680 KB Output is correct
8 Correct 64 ms 4820 KB Output is correct
9 Correct 62 ms 4820 KB Output is correct
10 Correct 64 ms 4840 KB Output is correct
11 Correct 61 ms 4840 KB Output is correct
12 Correct 59 ms 4840 KB Output is correct
13 Correct 59 ms 4840 KB Output is correct
14 Correct 63 ms 4840 KB Output is correct
15 Correct 59 ms 4844 KB Output is correct
16 Correct 54 ms 4844 KB Output is correct
17 Correct 55 ms 4844 KB Output is correct
18 Correct 55 ms 4844 KB Output is correct
19 Correct 56 ms 4844 KB Output is correct
20 Correct 55 ms 4844 KB Output is correct
21 Correct 843 ms 4844 KB Output is correct
22 Correct 837 ms 4860 KB Output is correct
23 Correct 778 ms 4884 KB Output is correct
24 Correct 817 ms 5020 KB Output is correct
25 Correct 854 ms 5020 KB Output is correct
26 Correct 1257 ms 5020 KB Output is correct
27 Correct 1323 ms 5044 KB Output is correct
28 Correct 1299 ms 5044 KB Output is correct
29 Correct 1299 ms 5044 KB Output is correct
30 Correct 66 ms 5068 KB Output is correct
31 Correct 62 ms 5080 KB Output is correct
32 Correct 66 ms 5080 KB Output is correct
33 Correct 66 ms 5104 KB Output is correct
34 Correct 66 ms 5108 KB Output is correct
35 Correct 66 ms 5124 KB Output is correct
36 Correct 62 ms 5140 KB Output is correct
37 Correct 64 ms 5268 KB Output is correct
38 Correct 62 ms 5268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5268 KB Output is correct
2 Correct 19 ms 5268 KB Output is correct
3 Correct 20 ms 5268 KB Output is correct
4 Correct 20 ms 5268 KB Output is correct
5 Correct 21 ms 5268 KB Output is correct
6 Correct 26 ms 5268 KB Output is correct
7 Correct 25 ms 5268 KB Output is correct
8 Correct 25 ms 5268 KB Output is correct
9 Correct 25 ms 5268 KB Output is correct
10 Correct 25 ms 5268 KB Output is correct
11 Correct 21 ms 5268 KB Output is correct
12 Correct 20 ms 5268 KB Output is correct
13 Correct 22 ms 5268 KB Output is correct
14 Correct 21 ms 5268 KB Output is correct
15 Correct 23 ms 5268 KB Output is correct
16 Correct 18 ms 5268 KB Output is correct
17 Correct 17 ms 5268 KB Output is correct
18 Correct 17 ms 5268 KB Output is correct
19 Correct 17 ms 5268 KB Output is correct
20 Correct 17 ms 5268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4344 KB Output is correct
2 Correct 60 ms 4400 KB Output is correct
3 Correct 60 ms 4416 KB Output is correct
4 Correct 62 ms 4488 KB Output is correct
5 Correct 59 ms 4548 KB Output is correct
6 Correct 59 ms 4560 KB Output is correct
7 Correct 62 ms 4680 KB Output is correct
8 Correct 64 ms 4820 KB Output is correct
9 Correct 62 ms 4820 KB Output is correct
10 Correct 64 ms 4840 KB Output is correct
11 Correct 61 ms 4840 KB Output is correct
12 Correct 59 ms 4840 KB Output is correct
13 Correct 59 ms 4840 KB Output is correct
14 Correct 63 ms 4840 KB Output is correct
15 Correct 59 ms 4844 KB Output is correct
16 Correct 54 ms 4844 KB Output is correct
17 Correct 55 ms 4844 KB Output is correct
18 Correct 55 ms 4844 KB Output is correct
19 Correct 56 ms 4844 KB Output is correct
20 Correct 55 ms 4844 KB Output is correct
21 Correct 843 ms 4844 KB Output is correct
22 Correct 837 ms 4860 KB Output is correct
23 Correct 778 ms 4884 KB Output is correct
24 Correct 817 ms 5020 KB Output is correct
25 Correct 854 ms 5020 KB Output is correct
26 Correct 1257 ms 5020 KB Output is correct
27 Correct 1323 ms 5044 KB Output is correct
28 Correct 1299 ms 5044 KB Output is correct
29 Correct 1299 ms 5044 KB Output is correct
30 Correct 66 ms 5068 KB Output is correct
31 Correct 62 ms 5080 KB Output is correct
32 Correct 66 ms 5080 KB Output is correct
33 Correct 66 ms 5104 KB Output is correct
34 Correct 66 ms 5108 KB Output is correct
35 Correct 66 ms 5124 KB Output is correct
36 Correct 62 ms 5140 KB Output is correct
37 Correct 64 ms 5268 KB Output is correct
38 Correct 62 ms 5268 KB Output is correct
39 Correct 21 ms 5268 KB Output is correct
40 Correct 19 ms 5268 KB Output is correct
41 Correct 20 ms 5268 KB Output is correct
42 Correct 20 ms 5268 KB Output is correct
43 Correct 21 ms 5268 KB Output is correct
44 Correct 26 ms 5268 KB Output is correct
45 Correct 25 ms 5268 KB Output is correct
46 Correct 25 ms 5268 KB Output is correct
47 Correct 25 ms 5268 KB Output is correct
48 Correct 25 ms 5268 KB Output is correct
49 Correct 21 ms 5268 KB Output is correct
50 Correct 20 ms 5268 KB Output is correct
51 Correct 22 ms 5268 KB Output is correct
52 Correct 21 ms 5268 KB Output is correct
53 Correct 23 ms 5268 KB Output is correct
54 Correct 18 ms 5268 KB Output is correct
55 Correct 17 ms 5268 KB Output is correct
56 Correct 17 ms 5268 KB Output is correct
57 Correct 17 ms 5268 KB Output is correct
58 Correct 17 ms 5268 KB Output is correct
59 Correct 965 ms 5416 KB Output is correct
60 Correct 911 ms 5420 KB Output is correct
61 Correct 892 ms 5420 KB Output is correct
62 Correct 991 ms 5420 KB Output is correct
63 Correct 946 ms 5420 KB Output is correct
64 Correct 1518 ms 5420 KB Output is correct
65 Correct 1548 ms 5616 KB Output is correct
66 Correct 1517 ms 5616 KB Output is correct
67 Correct 1531 ms 5616 KB Output is correct
68 Correct 1521 ms 5616 KB Output is correct
69 Correct 930 ms 5616 KB Output is correct
70 Correct 949 ms 5616 KB Output is correct
71 Correct 951 ms 5616 KB Output is correct
72 Correct 986 ms 5616 KB Output is correct
73 Correct 970 ms 5616 KB Output is correct
74 Correct 156 ms 5616 KB Output is correct
75 Correct 171 ms 5616 KB Output is correct
76 Correct 158 ms 5616 KB Output is correct
77 Correct 159 ms 5616 KB Output is correct
78 Correct 157 ms 5616 KB Output is correct