# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
34899 |
2017-11-16T16:33:38 Z |
cheater2k |
Boat (APIO16_boat) |
C++14 |
|
536 ms |
5240 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
const int md = 1e9 + 7;
int n;
int a[N], b[N];
vector<int> z;
int len[N * 2], sz;
int clen[N * 2][N], c[N][N];
int f[N], sum[N], g[N];
int pw(int a, int b) {
int res = 1;
while(b) {
if (b & 1) res = 1LL * res * a % md;
a = 1LL * a * a % md;
b >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i]; ++b[i];
z.push_back(a[i]); z.push_back(b[i]);
}
sort(z.begin(), z.end());
z.resize(distance(z.begin(), unique(z.begin(), z.end())));
for (int i = 0; i < (int)z.size() - 1; ++i) {
len[++sz] = z[i + 1] - z[i];
clen[sz][0] = 1;
for (int j = 1; j <= n; ++j) {
if (j > len[sz]) continue;
clen[sz][j] = 1LL * clen[sz][j-1] * (len[sz] - j + 1) % md;
clen[sz][j] = 1LL * clen[sz][j] * pw(j, md - 2) % md;
}
}
for (int i = 0; i <= n; ++i) c[i][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) c[i][j] = (c[i-1][j-1] + c[i-1][j]) % md;
}
for (int k = 1; k <= sz; ++k) {
vector<int> cand;
for (int i = 1; i <= n; ++i) {
if (a[i] <= z[k - 1] && z[k] <= b[i]) cand.push_back(i);
}
int s = cand.size();
for (int i = 0; i < s; ++i) {
if (i == 0) {
for (int gap = 0; gap <= s; ++gap) g[gap] = 0;
g[1] = len[k];
for (int j = 1; j < s; ++j) {
int gap = j - i + 1;
for (int choose = 2; choose <= gap && choose <= len[k]; ++choose) {
g[gap] = (g[gap] + 1LL * clen[k][choose] * c[gap-2][choose-2]) % md;
}
}
}
for (int j = i; j < s; ++j) {
f[j] = (f[j] + 1LL * g[j - i + 1] * (sum[cand[i]-1] + 1)) % md;
}
}
int cur = 0, pt = 0;
for (int i = 1; i <= n; ++i) {
while(pt < s && cand[pt] == i) cur = (cur + f[pt]) % md, f[pt] = 0, ++pt;
sum[i] = (sum[i] + cur) % md;
}
}
cout << sum[n] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
5240 KB |
Output is correct |
2 |
Correct |
63 ms |
5240 KB |
Output is correct |
3 |
Correct |
63 ms |
5240 KB |
Output is correct |
4 |
Correct |
63 ms |
5240 KB |
Output is correct |
5 |
Correct |
63 ms |
5240 KB |
Output is correct |
6 |
Correct |
59 ms |
5240 KB |
Output is correct |
7 |
Correct |
59 ms |
5240 KB |
Output is correct |
8 |
Correct |
56 ms |
5240 KB |
Output is correct |
9 |
Correct |
59 ms |
5240 KB |
Output is correct |
10 |
Correct |
56 ms |
5240 KB |
Output is correct |
11 |
Correct |
49 ms |
5240 KB |
Output is correct |
12 |
Correct |
56 ms |
5240 KB |
Output is correct |
13 |
Correct |
59 ms |
5240 KB |
Output is correct |
14 |
Correct |
59 ms |
5240 KB |
Output is correct |
15 |
Correct |
59 ms |
5240 KB |
Output is correct |
16 |
Correct |
9 ms |
5240 KB |
Output is correct |
17 |
Correct |
9 ms |
5240 KB |
Output is correct |
18 |
Correct |
9 ms |
5240 KB |
Output is correct |
19 |
Correct |
13 ms |
5240 KB |
Output is correct |
20 |
Correct |
9 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
5240 KB |
Output is correct |
2 |
Correct |
63 ms |
5240 KB |
Output is correct |
3 |
Correct |
63 ms |
5240 KB |
Output is correct |
4 |
Correct |
63 ms |
5240 KB |
Output is correct |
5 |
Correct |
63 ms |
5240 KB |
Output is correct |
6 |
Correct |
59 ms |
5240 KB |
Output is correct |
7 |
Correct |
59 ms |
5240 KB |
Output is correct |
8 |
Correct |
56 ms |
5240 KB |
Output is correct |
9 |
Correct |
59 ms |
5240 KB |
Output is correct |
10 |
Correct |
56 ms |
5240 KB |
Output is correct |
11 |
Correct |
49 ms |
5240 KB |
Output is correct |
12 |
Correct |
56 ms |
5240 KB |
Output is correct |
13 |
Correct |
59 ms |
5240 KB |
Output is correct |
14 |
Correct |
59 ms |
5240 KB |
Output is correct |
15 |
Correct |
59 ms |
5240 KB |
Output is correct |
16 |
Correct |
9 ms |
5240 KB |
Output is correct |
17 |
Correct |
9 ms |
5240 KB |
Output is correct |
18 |
Correct |
9 ms |
5240 KB |
Output is correct |
19 |
Correct |
13 ms |
5240 KB |
Output is correct |
20 |
Correct |
9 ms |
5240 KB |
Output is correct |
21 |
Correct |
66 ms |
5240 KB |
Output is correct |
22 |
Correct |
66 ms |
5240 KB |
Output is correct |
23 |
Correct |
59 ms |
5240 KB |
Output is correct |
24 |
Correct |
66 ms |
5240 KB |
Output is correct |
25 |
Correct |
63 ms |
5240 KB |
Output is correct |
26 |
Correct |
136 ms |
5240 KB |
Output is correct |
27 |
Correct |
139 ms |
5240 KB |
Output is correct |
28 |
Correct |
146 ms |
5240 KB |
Output is correct |
29 |
Correct |
133 ms |
5240 KB |
Output is correct |
30 |
Correct |
49 ms |
5240 KB |
Output is correct |
31 |
Correct |
53 ms |
5240 KB |
Output is correct |
32 |
Correct |
49 ms |
5240 KB |
Output is correct |
33 |
Correct |
49 ms |
5240 KB |
Output is correct |
34 |
Correct |
53 ms |
5240 KB |
Output is correct |
35 |
Correct |
53 ms |
5240 KB |
Output is correct |
36 |
Correct |
53 ms |
5240 KB |
Output is correct |
37 |
Correct |
56 ms |
5240 KB |
Output is correct |
38 |
Correct |
53 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
3 ms |
5240 KB |
Output is correct |
3 |
Correct |
6 ms |
5240 KB |
Output is correct |
4 |
Correct |
3 ms |
5240 KB |
Output is correct |
5 |
Correct |
6 ms |
5240 KB |
Output is correct |
6 |
Correct |
6 ms |
5240 KB |
Output is correct |
7 |
Correct |
6 ms |
5240 KB |
Output is correct |
8 |
Correct |
6 ms |
5240 KB |
Output is correct |
9 |
Correct |
6 ms |
5240 KB |
Output is correct |
10 |
Correct |
6 ms |
5240 KB |
Output is correct |
11 |
Correct |
6 ms |
5240 KB |
Output is correct |
12 |
Correct |
3 ms |
5240 KB |
Output is correct |
13 |
Correct |
3 ms |
5240 KB |
Output is correct |
14 |
Correct |
0 ms |
5240 KB |
Output is correct |
15 |
Correct |
3 ms |
5240 KB |
Output is correct |
16 |
Correct |
0 ms |
5240 KB |
Output is correct |
17 |
Correct |
3 ms |
5240 KB |
Output is correct |
18 |
Correct |
3 ms |
5240 KB |
Output is correct |
19 |
Correct |
3 ms |
5240 KB |
Output is correct |
20 |
Correct |
3 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
5240 KB |
Output is correct |
2 |
Correct |
63 ms |
5240 KB |
Output is correct |
3 |
Correct |
63 ms |
5240 KB |
Output is correct |
4 |
Correct |
63 ms |
5240 KB |
Output is correct |
5 |
Correct |
63 ms |
5240 KB |
Output is correct |
6 |
Correct |
59 ms |
5240 KB |
Output is correct |
7 |
Correct |
59 ms |
5240 KB |
Output is correct |
8 |
Correct |
56 ms |
5240 KB |
Output is correct |
9 |
Correct |
59 ms |
5240 KB |
Output is correct |
10 |
Correct |
56 ms |
5240 KB |
Output is correct |
11 |
Correct |
49 ms |
5240 KB |
Output is correct |
12 |
Correct |
56 ms |
5240 KB |
Output is correct |
13 |
Correct |
59 ms |
5240 KB |
Output is correct |
14 |
Correct |
59 ms |
5240 KB |
Output is correct |
15 |
Correct |
59 ms |
5240 KB |
Output is correct |
16 |
Correct |
9 ms |
5240 KB |
Output is correct |
17 |
Correct |
9 ms |
5240 KB |
Output is correct |
18 |
Correct |
9 ms |
5240 KB |
Output is correct |
19 |
Correct |
13 ms |
5240 KB |
Output is correct |
20 |
Correct |
9 ms |
5240 KB |
Output is correct |
21 |
Correct |
66 ms |
5240 KB |
Output is correct |
22 |
Correct |
66 ms |
5240 KB |
Output is correct |
23 |
Correct |
59 ms |
5240 KB |
Output is correct |
24 |
Correct |
66 ms |
5240 KB |
Output is correct |
25 |
Correct |
63 ms |
5240 KB |
Output is correct |
26 |
Correct |
136 ms |
5240 KB |
Output is correct |
27 |
Correct |
139 ms |
5240 KB |
Output is correct |
28 |
Correct |
146 ms |
5240 KB |
Output is correct |
29 |
Correct |
133 ms |
5240 KB |
Output is correct |
30 |
Correct |
49 ms |
5240 KB |
Output is correct |
31 |
Correct |
53 ms |
5240 KB |
Output is correct |
32 |
Correct |
49 ms |
5240 KB |
Output is correct |
33 |
Correct |
49 ms |
5240 KB |
Output is correct |
34 |
Correct |
53 ms |
5240 KB |
Output is correct |
35 |
Correct |
53 ms |
5240 KB |
Output is correct |
36 |
Correct |
53 ms |
5240 KB |
Output is correct |
37 |
Correct |
56 ms |
5240 KB |
Output is correct |
38 |
Correct |
53 ms |
5240 KB |
Output is correct |
39 |
Correct |
6 ms |
5240 KB |
Output is correct |
40 |
Correct |
3 ms |
5240 KB |
Output is correct |
41 |
Correct |
6 ms |
5240 KB |
Output is correct |
42 |
Correct |
3 ms |
5240 KB |
Output is correct |
43 |
Correct |
6 ms |
5240 KB |
Output is correct |
44 |
Correct |
6 ms |
5240 KB |
Output is correct |
45 |
Correct |
6 ms |
5240 KB |
Output is correct |
46 |
Correct |
6 ms |
5240 KB |
Output is correct |
47 |
Correct |
6 ms |
5240 KB |
Output is correct |
48 |
Correct |
6 ms |
5240 KB |
Output is correct |
49 |
Correct |
6 ms |
5240 KB |
Output is correct |
50 |
Correct |
3 ms |
5240 KB |
Output is correct |
51 |
Correct |
3 ms |
5240 KB |
Output is correct |
52 |
Correct |
0 ms |
5240 KB |
Output is correct |
53 |
Correct |
3 ms |
5240 KB |
Output is correct |
54 |
Correct |
0 ms |
5240 KB |
Output is correct |
55 |
Correct |
3 ms |
5240 KB |
Output is correct |
56 |
Correct |
3 ms |
5240 KB |
Output is correct |
57 |
Correct |
3 ms |
5240 KB |
Output is correct |
58 |
Correct |
3 ms |
5240 KB |
Output is correct |
59 |
Correct |
289 ms |
5240 KB |
Output is correct |
60 |
Correct |
273 ms |
5240 KB |
Output is correct |
61 |
Correct |
279 ms |
5240 KB |
Output is correct |
62 |
Correct |
303 ms |
5240 KB |
Output is correct |
63 |
Correct |
279 ms |
5240 KB |
Output is correct |
64 |
Correct |
513 ms |
5240 KB |
Output is correct |
65 |
Correct |
526 ms |
5240 KB |
Output is correct |
66 |
Correct |
529 ms |
5240 KB |
Output is correct |
67 |
Correct |
506 ms |
5240 KB |
Output is correct |
68 |
Correct |
536 ms |
5240 KB |
Output is correct |
69 |
Correct |
283 ms |
5240 KB |
Output is correct |
70 |
Correct |
269 ms |
5240 KB |
Output is correct |
71 |
Correct |
273 ms |
5240 KB |
Output is correct |
72 |
Correct |
269 ms |
5240 KB |
Output is correct |
73 |
Correct |
276 ms |
5240 KB |
Output is correct |
74 |
Correct |
36 ms |
5240 KB |
Output is correct |
75 |
Correct |
33 ms |
5240 KB |
Output is correct |
76 |
Correct |
33 ms |
5240 KB |
Output is correct |
77 |
Correct |
33 ms |
5240 KB |
Output is correct |
78 |
Correct |
36 ms |
5240 KB |
Output is correct |