///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 |
7 ms |
2300 KB |
Output is correct |
2 |
Correct |
7 ms |
2548 KB |
Output is correct |
3 |
Correct |
7 ms |
2612 KB |
Output is correct |
4 |
Correct |
7 ms |
2612 KB |
Output is correct |
5 |
Correct |
7 ms |
2612 KB |
Output is correct |
6 |
Correct |
7 ms |
2612 KB |
Output is correct |
7 |
Correct |
7 ms |
2612 KB |
Output is correct |
8 |
Correct |
7 ms |
2612 KB |
Output is correct |
9 |
Correct |
7 ms |
2612 KB |
Output is correct |
10 |
Correct |
7 ms |
2612 KB |
Output is correct |
11 |
Correct |
7 ms |
2612 KB |
Output is correct |
12 |
Correct |
6 ms |
2612 KB |
Output is correct |
13 |
Correct |
6 ms |
2612 KB |
Output is correct |
14 |
Correct |
7 ms |
2612 KB |
Output is correct |
15 |
Correct |
7 ms |
2612 KB |
Output is correct |
16 |
Correct |
5 ms |
2628 KB |
Output is correct |
17 |
Correct |
5 ms |
2764 KB |
Output is correct |
18 |
Correct |
5 ms |
2764 KB |
Output is correct |
19 |
Correct |
6 ms |
2764 KB |
Output is correct |
20 |
Correct |
6 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2300 KB |
Output is correct |
2 |
Correct |
7 ms |
2548 KB |
Output is correct |
3 |
Correct |
7 ms |
2612 KB |
Output is correct |
4 |
Correct |
7 ms |
2612 KB |
Output is correct |
5 |
Correct |
7 ms |
2612 KB |
Output is correct |
6 |
Correct |
7 ms |
2612 KB |
Output is correct |
7 |
Correct |
7 ms |
2612 KB |
Output is correct |
8 |
Correct |
7 ms |
2612 KB |
Output is correct |
9 |
Correct |
7 ms |
2612 KB |
Output is correct |
10 |
Correct |
7 ms |
2612 KB |
Output is correct |
11 |
Correct |
7 ms |
2612 KB |
Output is correct |
12 |
Correct |
6 ms |
2612 KB |
Output is correct |
13 |
Correct |
6 ms |
2612 KB |
Output is correct |
14 |
Correct |
7 ms |
2612 KB |
Output is correct |
15 |
Correct |
7 ms |
2612 KB |
Output is correct |
16 |
Correct |
5 ms |
2628 KB |
Output is correct |
17 |
Correct |
5 ms |
2764 KB |
Output is correct |
18 |
Correct |
5 ms |
2764 KB |
Output is correct |
19 |
Correct |
6 ms |
2764 KB |
Output is correct |
20 |
Correct |
6 ms |
2804 KB |
Output is correct |
21 |
Correct |
375 ms |
2804 KB |
Output is correct |
22 |
Correct |
363 ms |
2908 KB |
Output is correct |
23 |
Correct |
333 ms |
2908 KB |
Output is correct |
24 |
Correct |
354 ms |
2908 KB |
Output is correct |
25 |
Correct |
345 ms |
2924 KB |
Output is correct |
26 |
Correct |
570 ms |
3004 KB |
Output is correct |
27 |
Correct |
592 ms |
3004 KB |
Output is correct |
28 |
Correct |
561 ms |
3004 KB |
Output is correct |
29 |
Correct |
561 ms |
3004 KB |
Output is correct |
30 |
Correct |
9 ms |
3004 KB |
Output is correct |
31 |
Correct |
8 ms |
3004 KB |
Output is correct |
32 |
Correct |
8 ms |
3004 KB |
Output is correct |
33 |
Correct |
8 ms |
3004 KB |
Output is correct |
34 |
Correct |
9 ms |
3004 KB |
Output is correct |
35 |
Correct |
9 ms |
3004 KB |
Output is correct |
36 |
Correct |
9 ms |
3004 KB |
Output is correct |
37 |
Correct |
9 ms |
3004 KB |
Output is correct |
38 |
Correct |
9 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3004 KB |
Output is correct |
2 |
Correct |
4 ms |
3004 KB |
Output is correct |
3 |
Correct |
5 ms |
3004 KB |
Output is correct |
4 |
Correct |
5 ms |
3004 KB |
Output is correct |
5 |
Correct |
5 ms |
3004 KB |
Output is correct |
6 |
Correct |
7 ms |
3004 KB |
Output is correct |
7 |
Correct |
7 ms |
3004 KB |
Output is correct |
8 |
Correct |
7 ms |
3004 KB |
Output is correct |
9 |
Correct |
7 ms |
3004 KB |
Output is correct |
10 |
Correct |
7 ms |
3004 KB |
Output is correct |
11 |
Correct |
5 ms |
3004 KB |
Output is correct |
12 |
Correct |
4 ms |
3004 KB |
Output is correct |
13 |
Correct |
4 ms |
3004 KB |
Output is correct |
14 |
Correct |
5 ms |
3004 KB |
Output is correct |
15 |
Correct |
5 ms |
3004 KB |
Output is correct |
16 |
Correct |
13 ms |
3004 KB |
Output is correct |
17 |
Correct |
4 ms |
3004 KB |
Output is correct |
18 |
Correct |
4 ms |
3004 KB |
Output is correct |
19 |
Correct |
3 ms |
3004 KB |
Output is correct |
20 |
Correct |
4 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2300 KB |
Output is correct |
2 |
Correct |
7 ms |
2548 KB |
Output is correct |
3 |
Correct |
7 ms |
2612 KB |
Output is correct |
4 |
Correct |
7 ms |
2612 KB |
Output is correct |
5 |
Correct |
7 ms |
2612 KB |
Output is correct |
6 |
Correct |
7 ms |
2612 KB |
Output is correct |
7 |
Correct |
7 ms |
2612 KB |
Output is correct |
8 |
Correct |
7 ms |
2612 KB |
Output is correct |
9 |
Correct |
7 ms |
2612 KB |
Output is correct |
10 |
Correct |
7 ms |
2612 KB |
Output is correct |
11 |
Correct |
7 ms |
2612 KB |
Output is correct |
12 |
Correct |
6 ms |
2612 KB |
Output is correct |
13 |
Correct |
6 ms |
2612 KB |
Output is correct |
14 |
Correct |
7 ms |
2612 KB |
Output is correct |
15 |
Correct |
7 ms |
2612 KB |
Output is correct |
16 |
Correct |
5 ms |
2628 KB |
Output is correct |
17 |
Correct |
5 ms |
2764 KB |
Output is correct |
18 |
Correct |
5 ms |
2764 KB |
Output is correct |
19 |
Correct |
6 ms |
2764 KB |
Output is correct |
20 |
Correct |
6 ms |
2804 KB |
Output is correct |
21 |
Correct |
375 ms |
2804 KB |
Output is correct |
22 |
Correct |
363 ms |
2908 KB |
Output is correct |
23 |
Correct |
333 ms |
2908 KB |
Output is correct |
24 |
Correct |
354 ms |
2908 KB |
Output is correct |
25 |
Correct |
345 ms |
2924 KB |
Output is correct |
26 |
Correct |
570 ms |
3004 KB |
Output is correct |
27 |
Correct |
592 ms |
3004 KB |
Output is correct |
28 |
Correct |
561 ms |
3004 KB |
Output is correct |
29 |
Correct |
561 ms |
3004 KB |
Output is correct |
30 |
Correct |
9 ms |
3004 KB |
Output is correct |
31 |
Correct |
8 ms |
3004 KB |
Output is correct |
32 |
Correct |
8 ms |
3004 KB |
Output is correct |
33 |
Correct |
8 ms |
3004 KB |
Output is correct |
34 |
Correct |
9 ms |
3004 KB |
Output is correct |
35 |
Correct |
9 ms |
3004 KB |
Output is correct |
36 |
Correct |
9 ms |
3004 KB |
Output is correct |
37 |
Correct |
9 ms |
3004 KB |
Output is correct |
38 |
Correct |
9 ms |
3004 KB |
Output is correct |
39 |
Correct |
5 ms |
3004 KB |
Output is correct |
40 |
Correct |
4 ms |
3004 KB |
Output is correct |
41 |
Correct |
5 ms |
3004 KB |
Output is correct |
42 |
Correct |
5 ms |
3004 KB |
Output is correct |
43 |
Correct |
5 ms |
3004 KB |
Output is correct |
44 |
Correct |
7 ms |
3004 KB |
Output is correct |
45 |
Correct |
7 ms |
3004 KB |
Output is correct |
46 |
Correct |
7 ms |
3004 KB |
Output is correct |
47 |
Correct |
7 ms |
3004 KB |
Output is correct |
48 |
Correct |
7 ms |
3004 KB |
Output is correct |
49 |
Correct |
5 ms |
3004 KB |
Output is correct |
50 |
Correct |
4 ms |
3004 KB |
Output is correct |
51 |
Correct |
4 ms |
3004 KB |
Output is correct |
52 |
Correct |
5 ms |
3004 KB |
Output is correct |
53 |
Correct |
5 ms |
3004 KB |
Output is correct |
54 |
Correct |
13 ms |
3004 KB |
Output is correct |
55 |
Correct |
4 ms |
3004 KB |
Output is correct |
56 |
Correct |
4 ms |
3004 KB |
Output is correct |
57 |
Correct |
3 ms |
3004 KB |
Output is correct |
58 |
Correct |
4 ms |
3004 KB |
Output is correct |
59 |
Correct |
408 ms |
3124 KB |
Output is correct |
60 |
Correct |
369 ms |
3124 KB |
Output is correct |
61 |
Correct |
352 ms |
3180 KB |
Output is correct |
62 |
Correct |
390 ms |
3232 KB |
Output is correct |
63 |
Correct |
394 ms |
3232 KB |
Output is correct |
64 |
Correct |
661 ms |
3300 KB |
Output is correct |
65 |
Correct |
646 ms |
3336 KB |
Output is correct |
66 |
Correct |
654 ms |
3336 KB |
Output is correct |
67 |
Correct |
652 ms |
3336 KB |
Output is correct |
68 |
Correct |
660 ms |
3336 KB |
Output is correct |
69 |
Correct |
319 ms |
3336 KB |
Output is correct |
70 |
Correct |
312 ms |
3348 KB |
Output is correct |
71 |
Correct |
306 ms |
3348 KB |
Output is correct |
72 |
Correct |
316 ms |
3348 KB |
Output is correct |
73 |
Correct |
321 ms |
3348 KB |
Output is correct |
74 |
Correct |
84 ms |
3352 KB |
Output is correct |
75 |
Correct |
79 ms |
3352 KB |
Output is correct |
76 |
Correct |
161 ms |
3352 KB |
Output is correct |
77 |
Correct |
83 ms |
3352 KB |
Output is correct |
78 |
Correct |
81 ms |
3352 KB |
Output is correct |