#include<bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define IOS {cin.tie(0);ios_base::sync_with_stdio(false);}
#define N 505
#define int int64_t
const int MOD = 1000000007;
vector<int> ds;
int a[N],b[N];
int dp[N];
int inv[N];
int powmo(int a,int b,int m){
int r = 1;
for(;b;b>>=1){
if(b&1) r = r*a % m;
a = a*a % m;
}
return r;
}
int32_t main()
{
inv[0] = 1;
for(int i=1;i<N;i++) inv[i] = powmo(i,MOD-2,MOD);
IOS;
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i];
ds.push_back(a[i]);
ds.push_back(b[i]+1);
}
sort(ds.begin(),ds.end());
ds.resize(unique(ds.begin(),ds.end()) - ds.begin());
for(int i=1;i<=n;i++){
a[i] = (int)(lower_bound(ds.begin(),ds.end(),a[i]) - ds.begin());
b[i] = (int)(lower_bound(ds.begin(),ds.end(),b[i]+1) - ds.begin());
}
dp[0] = 1;
for(int i=0;i+1<ds.size();i++){
int L = ds[i+1] - ds[i];
for(int j=n;j>0;j--) if(a[j] <= i && i < b[j]){
int f = 0, c = L, m = 1;
for(int k=j-1;k>=0;k--){
(f += c * dp[k]) %= MOD;
if(a[k] <= i && i < b[k]) c = c * inv[m+1] % MOD * (L+m) % MOD,m++;
}
(dp[j] += f) %= MOD;
}
}
int ans = 0;
for(int i=1;i<=n;i++) (ans += dp[i]) %= MOD;
cout << ans << '\n';
return 0;
}
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i+1<ds.size();i++){
~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
428 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
412 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
428 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
412 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
247 ms |
504 KB |
Output is correct |
22 |
Correct |
242 ms |
384 KB |
Output is correct |
23 |
Correct |
220 ms |
384 KB |
Output is correct |
24 |
Correct |
259 ms |
504 KB |
Output is correct |
25 |
Correct |
245 ms |
504 KB |
Output is correct |
26 |
Correct |
506 ms |
504 KB |
Output is correct |
27 |
Correct |
529 ms |
384 KB |
Output is correct |
28 |
Correct |
507 ms |
452 KB |
Output is correct |
29 |
Correct |
519 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
6 ms |
384 KB |
Output is correct |
36 |
Correct |
7 ms |
384 KB |
Output is correct |
37 |
Correct |
6 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
356 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
428 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
412 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
247 ms |
504 KB |
Output is correct |
22 |
Correct |
242 ms |
384 KB |
Output is correct |
23 |
Correct |
220 ms |
384 KB |
Output is correct |
24 |
Correct |
259 ms |
504 KB |
Output is correct |
25 |
Correct |
245 ms |
504 KB |
Output is correct |
26 |
Correct |
506 ms |
504 KB |
Output is correct |
27 |
Correct |
529 ms |
384 KB |
Output is correct |
28 |
Correct |
507 ms |
452 KB |
Output is correct |
29 |
Correct |
519 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
6 ms |
384 KB |
Output is correct |
36 |
Correct |
7 ms |
384 KB |
Output is correct |
37 |
Correct |
6 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
384 KB |
Output is correct |
39 |
Correct |
6 ms |
384 KB |
Output is correct |
40 |
Correct |
4 ms |
384 KB |
Output is correct |
41 |
Correct |
4 ms |
384 KB |
Output is correct |
42 |
Correct |
4 ms |
384 KB |
Output is correct |
43 |
Correct |
4 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
384 KB |
Output is correct |
45 |
Correct |
6 ms |
384 KB |
Output is correct |
46 |
Correct |
7 ms |
384 KB |
Output is correct |
47 |
Correct |
7 ms |
384 KB |
Output is correct |
48 |
Correct |
6 ms |
384 KB |
Output is correct |
49 |
Correct |
4 ms |
384 KB |
Output is correct |
50 |
Correct |
3 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
356 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
4 ms |
384 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
4 ms |
384 KB |
Output is correct |
56 |
Correct |
4 ms |
384 KB |
Output is correct |
57 |
Correct |
4 ms |
384 KB |
Output is correct |
58 |
Correct |
4 ms |
384 KB |
Output is correct |
59 |
Correct |
287 ms |
416 KB |
Output is correct |
60 |
Correct |
260 ms |
504 KB |
Output is correct |
61 |
Correct |
248 ms |
504 KB |
Output is correct |
62 |
Correct |
282 ms |
504 KB |
Output is correct |
63 |
Correct |
260 ms |
384 KB |
Output is correct |
64 |
Correct |
570 ms |
504 KB |
Output is correct |
65 |
Correct |
613 ms |
476 KB |
Output is correct |
66 |
Correct |
573 ms |
384 KB |
Output is correct |
67 |
Correct |
586 ms |
504 KB |
Output is correct |
68 |
Correct |
578 ms |
504 KB |
Output is correct |
69 |
Correct |
211 ms |
504 KB |
Output is correct |
70 |
Correct |
215 ms |
384 KB |
Output is correct |
71 |
Correct |
227 ms |
504 KB |
Output is correct |
72 |
Correct |
229 ms |
384 KB |
Output is correct |
73 |
Correct |
230 ms |
384 KB |
Output is correct |
74 |
Correct |
55 ms |
504 KB |
Output is correct |
75 |
Correct |
51 ms |
504 KB |
Output is correct |
76 |
Correct |
52 ms |
384 KB |
Output is correct |
77 |
Correct |
62 ms |
504 KB |
Output is correct |
78 |
Correct |
62 ms |
504 KB |
Output is correct |