#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct interv{
int x, y;
};
interv a[501];
int n, sz;
int dif[2001];
int inv_mod[2001];
int d[501][2001];
int C[2001][2001], C2[501][501], Sum[2001][2001];
vector <int> v;
int lgput(int x, int p){
int aux = x, ans = 1;
for(int i = 1; i <= p ; i = i << 1){
if(i & p) ans = (1LL * ans * aux) % MOD;
aux = (1LL * aux * aux) % MOD;
}
return ans;
}
void calc_comb(int lin, int n, int k){
int prod = 1;
C[lin][0] = 1;
for(int i = 1; i <= k ; ++i){
prod = (1LL * prod * (n - i + 1)) % MOD;
prod = (1LL * prod * inv_mod[i]) % MOD;
C[lin][i] = prod;
}
}
void prec(){
C2[0][0] = 1;
for(int i = 1; i <= n ; ++i){
C2[i][0] = 1;
for(int j = 1; j <= i ; ++j){
C2[i][j] = C2[i - 1][j] + C2[i - 1][j - 1];
if(C2[i][j] >= MOD) C2[i][j] -= MOD;
}
}
for(int i = 1; i <= n ; ++i)
inv_mod[i] = lgput(i, MOD - 2);
for(int k = 2; k <= sz ; ++k)
calc_comb(k, dif[k], min(n, dif[k]));
for(int j = 2; j <= sz ; ++j){
for(int nr = 2; nr <= n ; ++nr){
for(int t = 2; t <= nr && t <= dif[j] ; ++t){
Sum[j][nr] = Sum[j][nr] + (1LL * C[j][t] * C2[nr - 2][t - 2]) % MOD;
if(Sum[j][nr] >= MOD) Sum[j][nr] -= MOD;
}
}
}
}
int main()
{
// freopen("1.in", "r", stdin);
scanf("%d", &n);
for(int i = 1; i <= n ; ++i){
scanf("%d%d", &a[i].x, &a[i].y);
v.push_back(a[i].x);
v.push_back(a[i].x - 1);
v.push_back(a[i].y);
v.push_back(a[i].y - 1);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
sz = v.size();
for(int i = 2; i <= sz ; ++i) dif[i] = v[i - 1] - v[i - 2];
for(int i = 1; i <= n ; ++i){
a[i].x = lower_bound(v.begin(), v.end(), a[i].x) - v.begin() + 1;
a[i].y = lower_bound(v.begin(), v.end(), a[i].y) - v.begin() + 1;
}
prec();
for(int j = 0; j <= sz ; ++j) d[0][j] = 1;
for(int j = a[1].x; j <= a[1].y ; ++j) d[1][j] = dif[j];
d[1][0] += 1;
for(int j = 1; j <= sz ; ++j){
d[1][j] += d[1][j - 1];
if(d[1][j] >= MOD) d[1][j] -= MOD;
}
for(int i = 2; i <= n ; ++i){
for(int j = a[i].x; j <= a[i].y ; ++j){
int nr = 0;
++nr;
d[i][j] = d[i][j] + (1LL * d[i - 1][j - 1] * dif[j]) % MOD;
if(d[i][j] >= MOD) d[i][j] -= MOD;
for(int k = i - 1; k >= 1 ; --k){
if(a[k].y < j || a[k].x > j) continue ;
++nr;
// int Sum = 0;
// for(int t = 2; t <= nr && t <= dif[j] ; ++t){
// Sum = Sum + (1LL * C[j][t] * C2[nr - 2][t - 2]) % MOD;
// if(Sum >= MOD) Sum -= MOD;
// }
d[i][j] = d[i][j] + (1LL * d[k - 1][j - 1] * Sum[j][nr]) % MOD;
if(d[i][j] >= MOD) d[i][j] -= MOD;
}
}
for(int j = 1; j <= sz ; ++j){
d[i][j] += d[i][j - 1];
if(d[i][j] >= MOD) d[i][j] -= MOD;
}
for(int j = 0; j <= sz ; ++j){
d[i][j] += d[i - 1][j];
if(d[i][j] >= MOD) d[i][j] -= MOD;
}
}
--d[n][sz];
if(d[n][sz] < 0) d[n][sz] += MOD;
printf("%d", d[n][sz]);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
boat.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i].x, &a[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
13164 KB |
Output is correct |
2 |
Correct |
269 ms |
13196 KB |
Output is correct |
3 |
Correct |
269 ms |
13252 KB |
Output is correct |
4 |
Correct |
269 ms |
13236 KB |
Output is correct |
5 |
Correct |
269 ms |
13188 KB |
Output is correct |
6 |
Correct |
269 ms |
13268 KB |
Output is correct |
7 |
Correct |
270 ms |
13288 KB |
Output is correct |
8 |
Correct |
271 ms |
13372 KB |
Output is correct |
9 |
Correct |
270 ms |
13352 KB |
Output is correct |
10 |
Correct |
270 ms |
13304 KB |
Output is correct |
11 |
Correct |
268 ms |
13348 KB |
Output is correct |
12 |
Correct |
407 ms |
13256 KB |
Output is correct |
13 |
Correct |
277 ms |
13304 KB |
Output is correct |
14 |
Correct |
277 ms |
13284 KB |
Output is correct |
15 |
Correct |
272 ms |
13304 KB |
Output is correct |
16 |
Correct |
58 ms |
5112 KB |
Output is correct |
17 |
Correct |
56 ms |
5152 KB |
Output is correct |
18 |
Correct |
54 ms |
5212 KB |
Output is correct |
19 |
Correct |
57 ms |
5240 KB |
Output is correct |
20 |
Correct |
54 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
13164 KB |
Output is correct |
2 |
Correct |
269 ms |
13196 KB |
Output is correct |
3 |
Correct |
269 ms |
13252 KB |
Output is correct |
4 |
Correct |
269 ms |
13236 KB |
Output is correct |
5 |
Correct |
269 ms |
13188 KB |
Output is correct |
6 |
Correct |
269 ms |
13268 KB |
Output is correct |
7 |
Correct |
270 ms |
13288 KB |
Output is correct |
8 |
Correct |
271 ms |
13372 KB |
Output is correct |
9 |
Correct |
270 ms |
13352 KB |
Output is correct |
10 |
Correct |
270 ms |
13304 KB |
Output is correct |
11 |
Correct |
268 ms |
13348 KB |
Output is correct |
12 |
Correct |
407 ms |
13256 KB |
Output is correct |
13 |
Correct |
277 ms |
13304 KB |
Output is correct |
14 |
Correct |
277 ms |
13284 KB |
Output is correct |
15 |
Correct |
272 ms |
13304 KB |
Output is correct |
16 |
Correct |
58 ms |
5112 KB |
Output is correct |
17 |
Correct |
56 ms |
5152 KB |
Output is correct |
18 |
Correct |
54 ms |
5212 KB |
Output is correct |
19 |
Correct |
57 ms |
5240 KB |
Output is correct |
20 |
Correct |
54 ms |
5212 KB |
Output is correct |
21 |
Correct |
231 ms |
15736 KB |
Output is correct |
22 |
Correct |
228 ms |
15668 KB |
Output is correct |
23 |
Correct |
207 ms |
15600 KB |
Output is correct |
24 |
Correct |
230 ms |
15864 KB |
Output is correct |
25 |
Correct |
221 ms |
15768 KB |
Output is correct |
26 |
Correct |
408 ms |
14968 KB |
Output is correct |
27 |
Correct |
404 ms |
14968 KB |
Output is correct |
28 |
Correct |
406 ms |
14840 KB |
Output is correct |
29 |
Correct |
421 ms |
14840 KB |
Output is correct |
30 |
Correct |
264 ms |
18808 KB |
Output is correct |
31 |
Correct |
265 ms |
18656 KB |
Output is correct |
32 |
Correct |
268 ms |
18608 KB |
Output is correct |
33 |
Correct |
268 ms |
18680 KB |
Output is correct |
34 |
Correct |
265 ms |
18736 KB |
Output is correct |
35 |
Correct |
258 ms |
13176 KB |
Output is correct |
36 |
Correct |
257 ms |
13176 KB |
Output is correct |
37 |
Correct |
262 ms |
13176 KB |
Output is correct |
38 |
Correct |
323 ms |
13176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3704 KB |
Output is correct |
2 |
Correct |
12 ms |
3704 KB |
Output is correct |
3 |
Correct |
12 ms |
3704 KB |
Output is correct |
4 |
Correct |
12 ms |
3704 KB |
Output is correct |
5 |
Correct |
12 ms |
3704 KB |
Output is correct |
6 |
Correct |
13 ms |
3704 KB |
Output is correct |
7 |
Correct |
13 ms |
3704 KB |
Output is correct |
8 |
Correct |
13 ms |
3704 KB |
Output is correct |
9 |
Correct |
14 ms |
3708 KB |
Output is correct |
10 |
Correct |
13 ms |
3704 KB |
Output is correct |
11 |
Correct |
11 ms |
3704 KB |
Output is correct |
12 |
Correct |
12 ms |
3624 KB |
Output is correct |
13 |
Correct |
12 ms |
3704 KB |
Output is correct |
14 |
Correct |
12 ms |
3704 KB |
Output is correct |
15 |
Correct |
12 ms |
3704 KB |
Output is correct |
16 |
Correct |
6 ms |
2168 KB |
Output is correct |
17 |
Correct |
6 ms |
2168 KB |
Output is correct |
18 |
Correct |
7 ms |
2168 KB |
Output is correct |
19 |
Correct |
13 ms |
2168 KB |
Output is correct |
20 |
Correct |
7 ms |
2168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
13164 KB |
Output is correct |
2 |
Correct |
269 ms |
13196 KB |
Output is correct |
3 |
Correct |
269 ms |
13252 KB |
Output is correct |
4 |
Correct |
269 ms |
13236 KB |
Output is correct |
5 |
Correct |
269 ms |
13188 KB |
Output is correct |
6 |
Correct |
269 ms |
13268 KB |
Output is correct |
7 |
Correct |
270 ms |
13288 KB |
Output is correct |
8 |
Correct |
271 ms |
13372 KB |
Output is correct |
9 |
Correct |
270 ms |
13352 KB |
Output is correct |
10 |
Correct |
270 ms |
13304 KB |
Output is correct |
11 |
Correct |
268 ms |
13348 KB |
Output is correct |
12 |
Correct |
407 ms |
13256 KB |
Output is correct |
13 |
Correct |
277 ms |
13304 KB |
Output is correct |
14 |
Correct |
277 ms |
13284 KB |
Output is correct |
15 |
Correct |
272 ms |
13304 KB |
Output is correct |
16 |
Correct |
58 ms |
5112 KB |
Output is correct |
17 |
Correct |
56 ms |
5152 KB |
Output is correct |
18 |
Correct |
54 ms |
5212 KB |
Output is correct |
19 |
Correct |
57 ms |
5240 KB |
Output is correct |
20 |
Correct |
54 ms |
5212 KB |
Output is correct |
21 |
Correct |
231 ms |
15736 KB |
Output is correct |
22 |
Correct |
228 ms |
15668 KB |
Output is correct |
23 |
Correct |
207 ms |
15600 KB |
Output is correct |
24 |
Correct |
230 ms |
15864 KB |
Output is correct |
25 |
Correct |
221 ms |
15768 KB |
Output is correct |
26 |
Correct |
408 ms |
14968 KB |
Output is correct |
27 |
Correct |
404 ms |
14968 KB |
Output is correct |
28 |
Correct |
406 ms |
14840 KB |
Output is correct |
29 |
Correct |
421 ms |
14840 KB |
Output is correct |
30 |
Correct |
264 ms |
18808 KB |
Output is correct |
31 |
Correct |
265 ms |
18656 KB |
Output is correct |
32 |
Correct |
268 ms |
18608 KB |
Output is correct |
33 |
Correct |
268 ms |
18680 KB |
Output is correct |
34 |
Correct |
265 ms |
18736 KB |
Output is correct |
35 |
Correct |
258 ms |
13176 KB |
Output is correct |
36 |
Correct |
257 ms |
13176 KB |
Output is correct |
37 |
Correct |
262 ms |
13176 KB |
Output is correct |
38 |
Correct |
323 ms |
13176 KB |
Output is correct |
39 |
Correct |
12 ms |
3704 KB |
Output is correct |
40 |
Correct |
12 ms |
3704 KB |
Output is correct |
41 |
Correct |
12 ms |
3704 KB |
Output is correct |
42 |
Correct |
12 ms |
3704 KB |
Output is correct |
43 |
Correct |
12 ms |
3704 KB |
Output is correct |
44 |
Correct |
13 ms |
3704 KB |
Output is correct |
45 |
Correct |
13 ms |
3704 KB |
Output is correct |
46 |
Correct |
13 ms |
3704 KB |
Output is correct |
47 |
Correct |
14 ms |
3708 KB |
Output is correct |
48 |
Correct |
13 ms |
3704 KB |
Output is correct |
49 |
Correct |
11 ms |
3704 KB |
Output is correct |
50 |
Correct |
12 ms |
3624 KB |
Output is correct |
51 |
Correct |
12 ms |
3704 KB |
Output is correct |
52 |
Correct |
12 ms |
3704 KB |
Output is correct |
53 |
Correct |
12 ms |
3704 KB |
Output is correct |
54 |
Correct |
6 ms |
2168 KB |
Output is correct |
55 |
Correct |
6 ms |
2168 KB |
Output is correct |
56 |
Correct |
7 ms |
2168 KB |
Output is correct |
57 |
Correct |
13 ms |
2168 KB |
Output is correct |
58 |
Correct |
7 ms |
2168 KB |
Output is correct |
59 |
Correct |
787 ms |
21160 KB |
Output is correct |
60 |
Correct |
753 ms |
21496 KB |
Output is correct |
61 |
Correct |
733 ms |
21368 KB |
Output is correct |
62 |
Correct |
767 ms |
21368 KB |
Output is correct |
63 |
Correct |
858 ms |
21260 KB |
Output is correct |
64 |
Correct |
1026 ms |
21240 KB |
Output is correct |
65 |
Correct |
1026 ms |
21316 KB |
Output is correct |
66 |
Correct |
1143 ms |
21240 KB |
Output is correct |
67 |
Correct |
1039 ms |
21224 KB |
Output is correct |
68 |
Correct |
1016 ms |
21240 KB |
Output is correct |
69 |
Correct |
715 ms |
21308 KB |
Output is correct |
70 |
Correct |
722 ms |
21240 KB |
Output is correct |
71 |
Correct |
723 ms |
21240 KB |
Output is correct |
72 |
Correct |
728 ms |
21280 KB |
Output is correct |
73 |
Correct |
742 ms |
21240 KB |
Output is correct |
74 |
Correct |
92 ms |
5368 KB |
Output is correct |
75 |
Correct |
88 ms |
5368 KB |
Output is correct |
76 |
Correct |
124 ms |
5368 KB |
Output is correct |
77 |
Correct |
89 ms |
5368 KB |
Output is correct |
78 |
Correct |
90 ms |
5368 KB |
Output is correct |