#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n, s[505], e[505], len[1005], cmpr[1005], segc;
ll dt[505][1005], sum[505][1005], minv[1005];
vector<ll> incl[1005];
ll bigpow (ll A, ll B) {
if(!B) return 1;
ll ret = bigpow(A,B/2);
ret = (ret*ret)%mod;
if(B%2) ret = (ret*A)%mod;
return ret;
}
int main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++) {
scanf("%lld%lld",&s[i],&e[i]); e[i]++;
cmpr[2*i-2] = s[i];
cmpr[2*i-1] = e[i];
}
cmpr[2*n] = 0; segc = 2*n+1;
sort(cmpr,cmpr+segc);
for(ll i=1;i<=n;i++) {
s[i] = lower_bound(cmpr,cmpr+segc,s[i])-cmpr;
e[i] = lower_bound(cmpr,cmpr+segc,e[i])-cmpr;
}
for(ll i=0;i<segc;i++) {
len[i] = cmpr[i+1]-cmpr[i];
for(ll j=1;j<=n;j++) {
if(s[j]<=i && i<e[j]) incl[i].push_back(j);
}
}
dt[0][0] = 1;
for(ll i=0;i<segc;i++) sum[0][i] = 1;
for(ll i=1;i<=n;i++) minv[i] = bigpow(i,mod-2);
for(ll i=1;i<=n;i++) {
for(ll j=0;j<segc;j++) {
if(s[i]>j || j>=e[i]) {
dt[i][j] = dt[i-1][j];
continue;
}
ll bnd = upper_bound(incl[j].begin(),incl[j].end(),i)-incl[j].begin()-1;
ll cnt = 1;
for(int k=0;k<=bnd;k++) {
cnt = ((cnt*(len[j]+k))%mod*minv[k+1])%mod;
dt[i][j] += cnt*sum[incl[j][bnd-k]-1][j-1];
dt[i][j] %= mod;
}
}
sum[i][0] = 1;
for(ll j=1;j<segc;j++) {
sum[i][j] = dt[i][j] + sum[i][j-1];
sum[i][j] %= mod;
}
}
printf("%lld\n",(sum[n][segc-1]+mod-1)%mod);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
boat.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&s[i],&e[i]); e[i]++;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8320 KB |
Output is correct |
2 |
Correct |
14 ms |
8312 KB |
Output is correct |
3 |
Correct |
14 ms |
8312 KB |
Output is correct |
4 |
Correct |
14 ms |
8312 KB |
Output is correct |
5 |
Correct |
14 ms |
8312 KB |
Output is correct |
6 |
Correct |
14 ms |
8316 KB |
Output is correct |
7 |
Correct |
14 ms |
8256 KB |
Output is correct |
8 |
Correct |
14 ms |
8284 KB |
Output is correct |
9 |
Correct |
14 ms |
8312 KB |
Output is correct |
10 |
Correct |
14 ms |
8312 KB |
Output is correct |
11 |
Correct |
14 ms |
8312 KB |
Output is correct |
12 |
Correct |
14 ms |
8312 KB |
Output is correct |
13 |
Correct |
14 ms |
8312 KB |
Output is correct |
14 |
Correct |
14 ms |
8312 KB |
Output is correct |
15 |
Correct |
14 ms |
8316 KB |
Output is correct |
16 |
Correct |
15 ms |
8312 KB |
Output is correct |
17 |
Correct |
15 ms |
8312 KB |
Output is correct |
18 |
Correct |
15 ms |
8340 KB |
Output is correct |
19 |
Correct |
14 ms |
8312 KB |
Output is correct |
20 |
Correct |
14 ms |
8312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8320 KB |
Output is correct |
2 |
Correct |
14 ms |
8312 KB |
Output is correct |
3 |
Correct |
14 ms |
8312 KB |
Output is correct |
4 |
Correct |
14 ms |
8312 KB |
Output is correct |
5 |
Correct |
14 ms |
8312 KB |
Output is correct |
6 |
Correct |
14 ms |
8316 KB |
Output is correct |
7 |
Correct |
14 ms |
8256 KB |
Output is correct |
8 |
Correct |
14 ms |
8284 KB |
Output is correct |
9 |
Correct |
14 ms |
8312 KB |
Output is correct |
10 |
Correct |
14 ms |
8312 KB |
Output is correct |
11 |
Correct |
14 ms |
8312 KB |
Output is correct |
12 |
Correct |
14 ms |
8312 KB |
Output is correct |
13 |
Correct |
14 ms |
8312 KB |
Output is correct |
14 |
Correct |
14 ms |
8312 KB |
Output is correct |
15 |
Correct |
14 ms |
8316 KB |
Output is correct |
16 |
Correct |
15 ms |
8312 KB |
Output is correct |
17 |
Correct |
15 ms |
8312 KB |
Output is correct |
18 |
Correct |
15 ms |
8340 KB |
Output is correct |
19 |
Correct |
14 ms |
8312 KB |
Output is correct |
20 |
Correct |
14 ms |
8312 KB |
Output is correct |
21 |
Correct |
292 ms |
10096 KB |
Output is correct |
22 |
Correct |
265 ms |
10104 KB |
Output is correct |
23 |
Correct |
226 ms |
9848 KB |
Output is correct |
24 |
Correct |
280 ms |
10044 KB |
Output is correct |
25 |
Correct |
265 ms |
10104 KB |
Output is correct |
26 |
Correct |
693 ms |
10928 KB |
Output is correct |
27 |
Correct |
621 ms |
11124 KB |
Output is correct |
28 |
Correct |
603 ms |
10872 KB |
Output is correct |
29 |
Correct |
608 ms |
11000 KB |
Output is correct |
30 |
Correct |
15 ms |
8312 KB |
Output is correct |
31 |
Correct |
15 ms |
8312 KB |
Output is correct |
32 |
Correct |
14 ms |
8312 KB |
Output is correct |
33 |
Correct |
14 ms |
8316 KB |
Output is correct |
34 |
Correct |
14 ms |
8312 KB |
Output is correct |
35 |
Correct |
14 ms |
8312 KB |
Output is correct |
36 |
Correct |
14 ms |
8312 KB |
Output is correct |
37 |
Correct |
14 ms |
8312 KB |
Output is correct |
38 |
Correct |
14 ms |
8312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1548 KB |
Output is correct |
3 |
Correct |
5 ms |
1532 KB |
Output is correct |
4 |
Correct |
5 ms |
1528 KB |
Output is correct |
5 |
Correct |
5 ms |
1528 KB |
Output is correct |
6 |
Correct |
8 ms |
1528 KB |
Output is correct |
7 |
Correct |
8 ms |
1532 KB |
Output is correct |
8 |
Correct |
8 ms |
1528 KB |
Output is correct |
9 |
Correct |
8 ms |
1528 KB |
Output is correct |
10 |
Correct |
8 ms |
1528 KB |
Output is correct |
11 |
Correct |
6 ms |
1528 KB |
Output is correct |
12 |
Correct |
5 ms |
1528 KB |
Output is correct |
13 |
Correct |
5 ms |
1528 KB |
Output is correct |
14 |
Correct |
5 ms |
1528 KB |
Output is correct |
15 |
Correct |
5 ms |
1528 KB |
Output is correct |
16 |
Correct |
5 ms |
1528 KB |
Output is correct |
17 |
Correct |
5 ms |
1528 KB |
Output is correct |
18 |
Correct |
5 ms |
1528 KB |
Output is correct |
19 |
Correct |
5 ms |
1528 KB |
Output is correct |
20 |
Correct |
5 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8320 KB |
Output is correct |
2 |
Correct |
14 ms |
8312 KB |
Output is correct |
3 |
Correct |
14 ms |
8312 KB |
Output is correct |
4 |
Correct |
14 ms |
8312 KB |
Output is correct |
5 |
Correct |
14 ms |
8312 KB |
Output is correct |
6 |
Correct |
14 ms |
8316 KB |
Output is correct |
7 |
Correct |
14 ms |
8256 KB |
Output is correct |
8 |
Correct |
14 ms |
8284 KB |
Output is correct |
9 |
Correct |
14 ms |
8312 KB |
Output is correct |
10 |
Correct |
14 ms |
8312 KB |
Output is correct |
11 |
Correct |
14 ms |
8312 KB |
Output is correct |
12 |
Correct |
14 ms |
8312 KB |
Output is correct |
13 |
Correct |
14 ms |
8312 KB |
Output is correct |
14 |
Correct |
14 ms |
8312 KB |
Output is correct |
15 |
Correct |
14 ms |
8316 KB |
Output is correct |
16 |
Correct |
15 ms |
8312 KB |
Output is correct |
17 |
Correct |
15 ms |
8312 KB |
Output is correct |
18 |
Correct |
15 ms |
8340 KB |
Output is correct |
19 |
Correct |
14 ms |
8312 KB |
Output is correct |
20 |
Correct |
14 ms |
8312 KB |
Output is correct |
21 |
Correct |
292 ms |
10096 KB |
Output is correct |
22 |
Correct |
265 ms |
10104 KB |
Output is correct |
23 |
Correct |
226 ms |
9848 KB |
Output is correct |
24 |
Correct |
280 ms |
10044 KB |
Output is correct |
25 |
Correct |
265 ms |
10104 KB |
Output is correct |
26 |
Correct |
693 ms |
10928 KB |
Output is correct |
27 |
Correct |
621 ms |
11124 KB |
Output is correct |
28 |
Correct |
603 ms |
10872 KB |
Output is correct |
29 |
Correct |
608 ms |
11000 KB |
Output is correct |
30 |
Correct |
15 ms |
8312 KB |
Output is correct |
31 |
Correct |
15 ms |
8312 KB |
Output is correct |
32 |
Correct |
14 ms |
8312 KB |
Output is correct |
33 |
Correct |
14 ms |
8316 KB |
Output is correct |
34 |
Correct |
14 ms |
8312 KB |
Output is correct |
35 |
Correct |
14 ms |
8312 KB |
Output is correct |
36 |
Correct |
14 ms |
8312 KB |
Output is correct |
37 |
Correct |
14 ms |
8312 KB |
Output is correct |
38 |
Correct |
14 ms |
8312 KB |
Output is correct |
39 |
Correct |
5 ms |
1528 KB |
Output is correct |
40 |
Correct |
5 ms |
1548 KB |
Output is correct |
41 |
Correct |
5 ms |
1532 KB |
Output is correct |
42 |
Correct |
5 ms |
1528 KB |
Output is correct |
43 |
Correct |
5 ms |
1528 KB |
Output is correct |
44 |
Correct |
8 ms |
1528 KB |
Output is correct |
45 |
Correct |
8 ms |
1532 KB |
Output is correct |
46 |
Correct |
8 ms |
1528 KB |
Output is correct |
47 |
Correct |
8 ms |
1528 KB |
Output is correct |
48 |
Correct |
8 ms |
1528 KB |
Output is correct |
49 |
Correct |
6 ms |
1528 KB |
Output is correct |
50 |
Correct |
5 ms |
1528 KB |
Output is correct |
51 |
Correct |
5 ms |
1528 KB |
Output is correct |
52 |
Correct |
5 ms |
1528 KB |
Output is correct |
53 |
Correct |
5 ms |
1528 KB |
Output is correct |
54 |
Correct |
5 ms |
1528 KB |
Output is correct |
55 |
Correct |
5 ms |
1528 KB |
Output is correct |
56 |
Correct |
5 ms |
1528 KB |
Output is correct |
57 |
Correct |
5 ms |
1528 KB |
Output is correct |
58 |
Correct |
5 ms |
1528 KB |
Output is correct |
59 |
Correct |
292 ms |
10096 KB |
Output is correct |
60 |
Correct |
236 ms |
9888 KB |
Output is correct |
61 |
Correct |
228 ms |
9884 KB |
Output is correct |
62 |
Correct |
274 ms |
10320 KB |
Output is correct |
63 |
Correct |
253 ms |
9848 KB |
Output is correct |
64 |
Correct |
604 ms |
11124 KB |
Output is correct |
65 |
Correct |
604 ms |
10872 KB |
Output is correct |
66 |
Correct |
605 ms |
10992 KB |
Output is correct |
67 |
Correct |
619 ms |
10844 KB |
Output is correct |
68 |
Correct |
605 ms |
11004 KB |
Output is correct |
69 |
Correct |
227 ms |
9980 KB |
Output is correct |
70 |
Correct |
234 ms |
9848 KB |
Output is correct |
71 |
Correct |
237 ms |
10112 KB |
Output is correct |
72 |
Correct |
247 ms |
9848 KB |
Output is correct |
73 |
Correct |
249 ms |
9976 KB |
Output is correct |
74 |
Correct |
270 ms |
9976 KB |
Output is correct |
75 |
Correct |
245 ms |
9856 KB |
Output is correct |
76 |
Correct |
262 ms |
9848 KB |
Output is correct |
77 |
Correct |
258 ms |
10084 KB |
Output is correct |
78 |
Correct |
282 ms |
10492 KB |
Output is correct |