#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
#define SZ(x) ((int)x.size())
const int mod = (int)1e9+7;
const int N = 505;
int n, f[N], g[N], ftmp[N], a[N], b[N], inv[N], tmp[N], m;
int choose[N][N], len[N<<1], lenCk[N<<1][N], c1[N];
vector<int> c;
int mul(int x, int y) {
x %= mod, y %= mod;
if (x < 0) x += mod;
if (y < 0) y += mod;
ll re = (ll)x * (ll)y % (ll)mod;
return (int)re;
}
void add(int &x, int y) {
x += y, x %= mod;
if (x < 0) x += mod;
}
int fast_pw(int x, int y) {
if (y == 1) return x % mod;
if (y == 0) return 1;
int t = fast_pw(x, y >> 1);
t = mul(t, t);
if (y & 1) t = mul(t, x);
return t;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
++b[i];
c.push_back(a[i]);
c.push_back(b[i]);
}
sort(c.begin(), c.end());
c.resize(distance(c.begin(), unique(c.begin(), c.end())));
for (int i = 0; i <= n; ++i) choose[i][i] = choose[i][0] = 1;
inv[0] = f[0] = g[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < i; ++j) choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % mod;
inv[i] = fast_pw(i, mod - 2);
g[i] = 1;
}
int sz = 0;
for (int i = 0; i < SZ(c); ++i) {
len[++sz] = c[i + 1] - c[i];
lenCk[sz][0] = 1;
for (int j = 1; j <= min(len[sz], n); ++j) {
lenCk[sz][j] = mul(lenCk[sz][j - 1], len[sz] - j + 1);
lenCk[sz][j] = mul(lenCk[sz][j], inv[j]);
}
}
for (int i = 1; i <= sz; ++i) {
m = 0;
for (int j = 1; j <= n; ++j)
if (a[j] <= c[i - 1] && c[i] <= b[j])
tmp[++m] = j;
for (int j = 1; j <= m; ++j) {
int id = tmp[j];
if (j == 1) {
for (int k = 0; k <= m; ++k) c1[k] = 0;
c1[1] = lenCk[i][1];
for (int k = 2; k <= m; ++k)
for (int x = 2; x <= min(k, len[i]); ++x)
add(c1[k], mul(lenCk[i][x], choose[k - 2][x - 2]));
}
for (int k = j; k <= m; ++k) {
int mid = k - j + 1, id2 = tmp[k];
add(ftmp[id2], mul(c1[mid], g[id - 1]));
}
}
g[0] = 1;
for (int j = 1; j <= n; ++j) {
add(f[j], ftmp[j]);
g[j] = (g[j - 1] + f[j]) % mod;
ftmp[j] = 0;
}
}
printf("%d", (g[n] - 1 + mod) % mod);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:40:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
boat.cpp:42:30: 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 |
13 ms |
3320 KB |
Output is correct |
2 |
Correct |
13 ms |
3424 KB |
Output is correct |
3 |
Correct |
12 ms |
3496 KB |
Output is correct |
4 |
Correct |
13 ms |
3496 KB |
Output is correct |
5 |
Correct |
12 ms |
3496 KB |
Output is correct |
6 |
Correct |
12 ms |
3620 KB |
Output is correct |
7 |
Correct |
12 ms |
3620 KB |
Output is correct |
8 |
Correct |
12 ms |
3620 KB |
Output is correct |
9 |
Correct |
12 ms |
3620 KB |
Output is correct |
10 |
Correct |
13 ms |
3620 KB |
Output is correct |
11 |
Correct |
15 ms |
3620 KB |
Output is correct |
12 |
Correct |
13 ms |
3620 KB |
Output is correct |
13 |
Correct |
12 ms |
3620 KB |
Output is correct |
14 |
Correct |
12 ms |
3620 KB |
Output is correct |
15 |
Correct |
12 ms |
3620 KB |
Output is correct |
16 |
Correct |
5 ms |
3620 KB |
Output is correct |
17 |
Correct |
5 ms |
3620 KB |
Output is correct |
18 |
Correct |
5 ms |
3620 KB |
Output is correct |
19 |
Correct |
5 ms |
3620 KB |
Output is correct |
20 |
Correct |
6 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3320 KB |
Output is correct |
2 |
Correct |
13 ms |
3424 KB |
Output is correct |
3 |
Correct |
12 ms |
3496 KB |
Output is correct |
4 |
Correct |
13 ms |
3496 KB |
Output is correct |
5 |
Correct |
12 ms |
3496 KB |
Output is correct |
6 |
Correct |
12 ms |
3620 KB |
Output is correct |
7 |
Correct |
12 ms |
3620 KB |
Output is correct |
8 |
Correct |
12 ms |
3620 KB |
Output is correct |
9 |
Correct |
12 ms |
3620 KB |
Output is correct |
10 |
Correct |
13 ms |
3620 KB |
Output is correct |
11 |
Correct |
15 ms |
3620 KB |
Output is correct |
12 |
Correct |
13 ms |
3620 KB |
Output is correct |
13 |
Correct |
12 ms |
3620 KB |
Output is correct |
14 |
Correct |
12 ms |
3620 KB |
Output is correct |
15 |
Correct |
12 ms |
3620 KB |
Output is correct |
16 |
Correct |
5 ms |
3620 KB |
Output is correct |
17 |
Correct |
5 ms |
3620 KB |
Output is correct |
18 |
Correct |
5 ms |
3620 KB |
Output is correct |
19 |
Correct |
5 ms |
3620 KB |
Output is correct |
20 |
Correct |
6 ms |
3620 KB |
Output is correct |
21 |
Correct |
157 ms |
3620 KB |
Output is correct |
22 |
Correct |
152 ms |
3620 KB |
Output is correct |
23 |
Correct |
132 ms |
3620 KB |
Output is correct |
24 |
Correct |
151 ms |
3620 KB |
Output is correct |
25 |
Correct |
153 ms |
3620 KB |
Output is correct |
26 |
Correct |
324 ms |
3620 KB |
Output is correct |
27 |
Correct |
354 ms |
3620 KB |
Output is correct |
28 |
Correct |
373 ms |
3620 KB |
Output is correct |
29 |
Correct |
329 ms |
3620 KB |
Output is correct |
30 |
Correct |
11 ms |
3620 KB |
Output is correct |
31 |
Correct |
10 ms |
3620 KB |
Output is correct |
32 |
Correct |
11 ms |
3648 KB |
Output is correct |
33 |
Correct |
11 ms |
3648 KB |
Output is correct |
34 |
Correct |
11 ms |
3648 KB |
Output is correct |
35 |
Correct |
11 ms |
3648 KB |
Output is correct |
36 |
Correct |
16 ms |
3648 KB |
Output is correct |
37 |
Correct |
12 ms |
3648 KB |
Output is correct |
38 |
Correct |
11 ms |
3648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3648 KB |
Output is correct |
2 |
Correct |
4 ms |
3648 KB |
Output is correct |
3 |
Correct |
5 ms |
3648 KB |
Output is correct |
4 |
Correct |
5 ms |
3648 KB |
Output is correct |
5 |
Correct |
5 ms |
3648 KB |
Output is correct |
6 |
Correct |
8 ms |
3648 KB |
Output is correct |
7 |
Correct |
9 ms |
3648 KB |
Output is correct |
8 |
Correct |
10 ms |
3648 KB |
Output is correct |
9 |
Correct |
9 ms |
3648 KB |
Output is correct |
10 |
Correct |
10 ms |
3648 KB |
Output is correct |
11 |
Correct |
5 ms |
3648 KB |
Output is correct |
12 |
Correct |
4 ms |
3648 KB |
Output is correct |
13 |
Correct |
5 ms |
3648 KB |
Output is correct |
14 |
Correct |
5 ms |
3648 KB |
Output is correct |
15 |
Correct |
5 ms |
3648 KB |
Output is correct |
16 |
Correct |
4 ms |
3648 KB |
Output is correct |
17 |
Correct |
4 ms |
3648 KB |
Output is correct |
18 |
Correct |
3 ms |
3648 KB |
Output is correct |
19 |
Correct |
3 ms |
3648 KB |
Output is correct |
20 |
Correct |
3 ms |
3648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3320 KB |
Output is correct |
2 |
Correct |
13 ms |
3424 KB |
Output is correct |
3 |
Correct |
12 ms |
3496 KB |
Output is correct |
4 |
Correct |
13 ms |
3496 KB |
Output is correct |
5 |
Correct |
12 ms |
3496 KB |
Output is correct |
6 |
Correct |
12 ms |
3620 KB |
Output is correct |
7 |
Correct |
12 ms |
3620 KB |
Output is correct |
8 |
Correct |
12 ms |
3620 KB |
Output is correct |
9 |
Correct |
12 ms |
3620 KB |
Output is correct |
10 |
Correct |
13 ms |
3620 KB |
Output is correct |
11 |
Correct |
15 ms |
3620 KB |
Output is correct |
12 |
Correct |
13 ms |
3620 KB |
Output is correct |
13 |
Correct |
12 ms |
3620 KB |
Output is correct |
14 |
Correct |
12 ms |
3620 KB |
Output is correct |
15 |
Correct |
12 ms |
3620 KB |
Output is correct |
16 |
Correct |
5 ms |
3620 KB |
Output is correct |
17 |
Correct |
5 ms |
3620 KB |
Output is correct |
18 |
Correct |
5 ms |
3620 KB |
Output is correct |
19 |
Correct |
5 ms |
3620 KB |
Output is correct |
20 |
Correct |
6 ms |
3620 KB |
Output is correct |
21 |
Correct |
157 ms |
3620 KB |
Output is correct |
22 |
Correct |
152 ms |
3620 KB |
Output is correct |
23 |
Correct |
132 ms |
3620 KB |
Output is correct |
24 |
Correct |
151 ms |
3620 KB |
Output is correct |
25 |
Correct |
153 ms |
3620 KB |
Output is correct |
26 |
Correct |
324 ms |
3620 KB |
Output is correct |
27 |
Correct |
354 ms |
3620 KB |
Output is correct |
28 |
Correct |
373 ms |
3620 KB |
Output is correct |
29 |
Correct |
329 ms |
3620 KB |
Output is correct |
30 |
Correct |
11 ms |
3620 KB |
Output is correct |
31 |
Correct |
10 ms |
3620 KB |
Output is correct |
32 |
Correct |
11 ms |
3648 KB |
Output is correct |
33 |
Correct |
11 ms |
3648 KB |
Output is correct |
34 |
Correct |
11 ms |
3648 KB |
Output is correct |
35 |
Correct |
11 ms |
3648 KB |
Output is correct |
36 |
Correct |
16 ms |
3648 KB |
Output is correct |
37 |
Correct |
12 ms |
3648 KB |
Output is correct |
38 |
Correct |
11 ms |
3648 KB |
Output is correct |
39 |
Correct |
5 ms |
3648 KB |
Output is correct |
40 |
Correct |
4 ms |
3648 KB |
Output is correct |
41 |
Correct |
5 ms |
3648 KB |
Output is correct |
42 |
Correct |
5 ms |
3648 KB |
Output is correct |
43 |
Correct |
5 ms |
3648 KB |
Output is correct |
44 |
Correct |
8 ms |
3648 KB |
Output is correct |
45 |
Correct |
9 ms |
3648 KB |
Output is correct |
46 |
Correct |
10 ms |
3648 KB |
Output is correct |
47 |
Correct |
9 ms |
3648 KB |
Output is correct |
48 |
Correct |
10 ms |
3648 KB |
Output is correct |
49 |
Correct |
5 ms |
3648 KB |
Output is correct |
50 |
Correct |
4 ms |
3648 KB |
Output is correct |
51 |
Correct |
5 ms |
3648 KB |
Output is correct |
52 |
Correct |
5 ms |
3648 KB |
Output is correct |
53 |
Correct |
5 ms |
3648 KB |
Output is correct |
54 |
Correct |
4 ms |
3648 KB |
Output is correct |
55 |
Correct |
4 ms |
3648 KB |
Output is correct |
56 |
Correct |
3 ms |
3648 KB |
Output is correct |
57 |
Correct |
3 ms |
3648 KB |
Output is correct |
58 |
Correct |
3 ms |
3648 KB |
Output is correct |
59 |
Correct |
345 ms |
3692 KB |
Output is correct |
60 |
Correct |
305 ms |
3692 KB |
Output is correct |
61 |
Correct |
306 ms |
3692 KB |
Output is correct |
62 |
Correct |
352 ms |
3692 KB |
Output is correct |
63 |
Correct |
325 ms |
3692 KB |
Output is correct |
64 |
Correct |
776 ms |
3692 KB |
Output is correct |
65 |
Correct |
782 ms |
3692 KB |
Output is correct |
66 |
Correct |
818 ms |
3692 KB |
Output is correct |
67 |
Correct |
796 ms |
3692 KB |
Output is correct |
68 |
Correct |
812 ms |
3692 KB |
Output is correct |
69 |
Correct |
292 ms |
3692 KB |
Output is correct |
70 |
Correct |
300 ms |
3692 KB |
Output is correct |
71 |
Correct |
296 ms |
3692 KB |
Output is correct |
72 |
Correct |
335 ms |
3692 KB |
Output is correct |
73 |
Correct |
329 ms |
3692 KB |
Output is correct |
74 |
Correct |
54 ms |
3692 KB |
Output is correct |
75 |
Correct |
49 ms |
3692 KB |
Output is correct |
76 |
Correct |
53 ms |
3692 KB |
Output is correct |
77 |
Correct |
55 ms |
3692 KB |
Output is correct |
78 |
Correct |
56 ms |
3692 KB |
Output is correct |