///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1024;
const int mod = 1e9 + 7;
int n, a[N], b[N], dp[N][N], inv[N], len[N];
vector<int> v;
void add(int &a, int b) { if((a += b) >= mod) a -= mod; }
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d %d", &a[i], &b[i]);
v.push_back(a[i]);
v.push_back(++b[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i = 1; i <= n; ++i) {
a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin() + 1;
}
inv[1] = 1;
for(int i = 2; i <= n; ++i)
inv[i] = (ll) (mod - mod / i) * inv[mod % i] % mod;
int m = v.size() - 1;
for(int i = 1; i <= m; ++i) len[i] = v[i] - v[i - 1];
for(int i = 0; i <= m; ++i) dp[0][i] = 1;
for(int i = 1; i <= n; ++i) {
for(int j = a[i]; j < b[i]; ++j) {
int prod = len[j], cnt = 1;
for(int k = i - 1; k >= 0; --k) {
add(dp[i][j], (ll) dp[k][j - 1] * prod % mod);
if(a[k] <= j && j < b[k]) {
++cnt;
prod = (ll) prod * (len[j] + cnt - 1) % mod;
prod = (ll) prod * inv[cnt] % mod;
}
}
}
for(int j = 1; j <= m; ++j) add(dp[i][j], dp[i][j - 1]);
}
int ans = 0;
for(int i = 1; i <= n; ++i)
add(ans, dp[i][m]);
printf("%d\n", ans);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2424 KB |
Output is correct |
2 |
Correct |
6 ms |
2556 KB |
Output is correct |
3 |
Correct |
6 ms |
2556 KB |
Output is correct |
4 |
Correct |
6 ms |
2556 KB |
Output is correct |
5 |
Correct |
6 ms |
2556 KB |
Output is correct |
6 |
Correct |
6 ms |
2584 KB |
Output is correct |
7 |
Correct |
6 ms |
2584 KB |
Output is correct |
8 |
Correct |
6 ms |
2584 KB |
Output is correct |
9 |
Correct |
6 ms |
2584 KB |
Output is correct |
10 |
Correct |
6 ms |
2644 KB |
Output is correct |
11 |
Correct |
7 ms |
2644 KB |
Output is correct |
12 |
Correct |
7 ms |
2644 KB |
Output is correct |
13 |
Correct |
7 ms |
2644 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2644 KB |
Output is correct |
16 |
Correct |
6 ms |
2668 KB |
Output is correct |
17 |
Correct |
6 ms |
2668 KB |
Output is correct |
18 |
Correct |
5 ms |
2668 KB |
Output is correct |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
5 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2424 KB |
Output is correct |
2 |
Correct |
6 ms |
2556 KB |
Output is correct |
3 |
Correct |
6 ms |
2556 KB |
Output is correct |
4 |
Correct |
6 ms |
2556 KB |
Output is correct |
5 |
Correct |
6 ms |
2556 KB |
Output is correct |
6 |
Correct |
6 ms |
2584 KB |
Output is correct |
7 |
Correct |
6 ms |
2584 KB |
Output is correct |
8 |
Correct |
6 ms |
2584 KB |
Output is correct |
9 |
Correct |
6 ms |
2584 KB |
Output is correct |
10 |
Correct |
6 ms |
2644 KB |
Output is correct |
11 |
Correct |
7 ms |
2644 KB |
Output is correct |
12 |
Correct |
7 ms |
2644 KB |
Output is correct |
13 |
Correct |
7 ms |
2644 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2644 KB |
Output is correct |
16 |
Correct |
6 ms |
2668 KB |
Output is correct |
17 |
Correct |
6 ms |
2668 KB |
Output is correct |
18 |
Correct |
5 ms |
2668 KB |
Output is correct |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
5 ms |
2668 KB |
Output is correct |
21 |
Correct |
374 ms |
2668 KB |
Output is correct |
22 |
Correct |
355 ms |
2668 KB |
Output is correct |
23 |
Correct |
327 ms |
2668 KB |
Output is correct |
24 |
Correct |
339 ms |
2668 KB |
Output is correct |
25 |
Correct |
341 ms |
2816 KB |
Output is correct |
26 |
Correct |
573 ms |
2816 KB |
Output is correct |
27 |
Correct |
581 ms |
2816 KB |
Output is correct |
28 |
Correct |
570 ms |
2816 KB |
Output is correct |
29 |
Correct |
561 ms |
2816 KB |
Output is correct |
30 |
Correct |
9 ms |
2816 KB |
Output is correct |
31 |
Correct |
8 ms |
2816 KB |
Output is correct |
32 |
Correct |
9 ms |
2816 KB |
Output is correct |
33 |
Correct |
8 ms |
2816 KB |
Output is correct |
34 |
Correct |
8 ms |
2816 KB |
Output is correct |
35 |
Correct |
8 ms |
2816 KB |
Output is correct |
36 |
Correct |
9 ms |
2816 KB |
Output is correct |
37 |
Correct |
9 ms |
2816 KB |
Output is correct |
38 |
Correct |
9 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2816 KB |
Output is correct |
2 |
Correct |
4 ms |
2816 KB |
Output is correct |
3 |
Correct |
4 ms |
2816 KB |
Output is correct |
4 |
Correct |
5 ms |
2816 KB |
Output is correct |
5 |
Correct |
5 ms |
2816 KB |
Output is correct |
6 |
Correct |
7 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2816 KB |
Output is correct |
10 |
Correct |
7 ms |
2816 KB |
Output is correct |
11 |
Correct |
5 ms |
2816 KB |
Output is correct |
12 |
Correct |
4 ms |
2816 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2816 KB |
Output is correct |
15 |
Correct |
4 ms |
2816 KB |
Output is correct |
16 |
Correct |
4 ms |
2816 KB |
Output is correct |
17 |
Correct |
4 ms |
2816 KB |
Output is correct |
18 |
Correct |
4 ms |
2816 KB |
Output is correct |
19 |
Correct |
3 ms |
2816 KB |
Output is correct |
20 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2424 KB |
Output is correct |
2 |
Correct |
6 ms |
2556 KB |
Output is correct |
3 |
Correct |
6 ms |
2556 KB |
Output is correct |
4 |
Correct |
6 ms |
2556 KB |
Output is correct |
5 |
Correct |
6 ms |
2556 KB |
Output is correct |
6 |
Correct |
6 ms |
2584 KB |
Output is correct |
7 |
Correct |
6 ms |
2584 KB |
Output is correct |
8 |
Correct |
6 ms |
2584 KB |
Output is correct |
9 |
Correct |
6 ms |
2584 KB |
Output is correct |
10 |
Correct |
6 ms |
2644 KB |
Output is correct |
11 |
Correct |
7 ms |
2644 KB |
Output is correct |
12 |
Correct |
7 ms |
2644 KB |
Output is correct |
13 |
Correct |
7 ms |
2644 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2644 KB |
Output is correct |
16 |
Correct |
6 ms |
2668 KB |
Output is correct |
17 |
Correct |
6 ms |
2668 KB |
Output is correct |
18 |
Correct |
5 ms |
2668 KB |
Output is correct |
19 |
Correct |
6 ms |
2668 KB |
Output is correct |
20 |
Correct |
5 ms |
2668 KB |
Output is correct |
21 |
Correct |
374 ms |
2668 KB |
Output is correct |
22 |
Correct |
355 ms |
2668 KB |
Output is correct |
23 |
Correct |
327 ms |
2668 KB |
Output is correct |
24 |
Correct |
339 ms |
2668 KB |
Output is correct |
25 |
Correct |
341 ms |
2816 KB |
Output is correct |
26 |
Correct |
573 ms |
2816 KB |
Output is correct |
27 |
Correct |
581 ms |
2816 KB |
Output is correct |
28 |
Correct |
570 ms |
2816 KB |
Output is correct |
29 |
Correct |
561 ms |
2816 KB |
Output is correct |
30 |
Correct |
9 ms |
2816 KB |
Output is correct |
31 |
Correct |
8 ms |
2816 KB |
Output is correct |
32 |
Correct |
9 ms |
2816 KB |
Output is correct |
33 |
Correct |
8 ms |
2816 KB |
Output is correct |
34 |
Correct |
8 ms |
2816 KB |
Output is correct |
35 |
Correct |
8 ms |
2816 KB |
Output is correct |
36 |
Correct |
9 ms |
2816 KB |
Output is correct |
37 |
Correct |
9 ms |
2816 KB |
Output is correct |
38 |
Correct |
9 ms |
2816 KB |
Output is correct |
39 |
Correct |
5 ms |
2816 KB |
Output is correct |
40 |
Correct |
4 ms |
2816 KB |
Output is correct |
41 |
Correct |
4 ms |
2816 KB |
Output is correct |
42 |
Correct |
5 ms |
2816 KB |
Output is correct |
43 |
Correct |
5 ms |
2816 KB |
Output is correct |
44 |
Correct |
7 ms |
2816 KB |
Output is correct |
45 |
Correct |
7 ms |
2816 KB |
Output is correct |
46 |
Correct |
7 ms |
2816 KB |
Output is correct |
47 |
Correct |
7 ms |
2816 KB |
Output is correct |
48 |
Correct |
7 ms |
2816 KB |
Output is correct |
49 |
Correct |
5 ms |
2816 KB |
Output is correct |
50 |
Correct |
4 ms |
2816 KB |
Output is correct |
51 |
Correct |
4 ms |
2816 KB |
Output is correct |
52 |
Correct |
4 ms |
2816 KB |
Output is correct |
53 |
Correct |
4 ms |
2816 KB |
Output is correct |
54 |
Correct |
4 ms |
2816 KB |
Output is correct |
55 |
Correct |
4 ms |
2816 KB |
Output is correct |
56 |
Correct |
4 ms |
2816 KB |
Output is correct |
57 |
Correct |
3 ms |
2816 KB |
Output is correct |
58 |
Correct |
4 ms |
2816 KB |
Output is correct |
59 |
Correct |
404 ms |
2816 KB |
Output is correct |
60 |
Correct |
377 ms |
2816 KB |
Output is correct |
61 |
Correct |
351 ms |
2816 KB |
Output is correct |
62 |
Correct |
382 ms |
2816 KB |
Output is correct |
63 |
Correct |
387 ms |
2816 KB |
Output is correct |
64 |
Correct |
642 ms |
2816 KB |
Output is correct |
65 |
Correct |
642 ms |
2816 KB |
Output is correct |
66 |
Correct |
642 ms |
2816 KB |
Output is correct |
67 |
Correct |
657 ms |
2816 KB |
Output is correct |
68 |
Correct |
660 ms |
2816 KB |
Output is correct |
69 |
Correct |
320 ms |
2816 KB |
Output is correct |
70 |
Correct |
308 ms |
2816 KB |
Output is correct |
71 |
Correct |
302 ms |
2816 KB |
Output is correct |
72 |
Correct |
325 ms |
2816 KB |
Output is correct |
73 |
Correct |
329 ms |
2816 KB |
Output is correct |
74 |
Correct |
81 ms |
2816 KB |
Output is correct |
75 |
Correct |
74 ms |
2816 KB |
Output is correct |
76 |
Correct |
80 ms |
2816 KB |
Output is correct |
77 |
Correct |
82 ms |
2816 KB |
Output is correct |
78 |
Correct |
80 ms |
2816 KB |
Output is correct |