//曇り空 のぞいた予感
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1010;
const ll mod = 1e9+7;
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
vector < int > vec;
int n , m , inv[maxn];
int l[maxn] , r[maxn];
int dp[maxn][maxn*2];
int ans;
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
for(int i = 1 ; i < maxn ; i ++)inv[i] = pw(i , mod - 2);
cin >> n;
for(int i = 1 ; i <= n ; i ++)
cin >> l[i] >> r[i] , r[i]++ , vec.pb(l[i]) , vec.pb(r[i]);
sort(vec.begin() , vec.end());
vec.resize(unique(vec.begin() , vec.end()) - vec.begin());
m = vec.size();
for(int i = 0 ; i < m ; i ++)dp[0][i] = 1;
for(int i = 1 ; i <= n ; i ++)
l[i] = lower_bound(vec.begin() , vec.end() , l[i])-vec.begin()+1,
r[i] = lower_bound(vec.begin() , vec.end() , r[i])-vec.begin()+1;
for(int i = 1 ; i <= n ; i ++){
for(int j = l[i] ; j < r[i] ; j ++){
ll C = vec[j]-vec[j-1];
ll x = vec[j]-vec[j-1], y = 1;
for(int k = i-1 ; k >= 0 ; k --){
dp[i][j] = (dp[i][j] + (dp[k][j-1] * 1ll * C)%mod)%mod;
if(l[k] <= j and j < r[k]){
x++ , ++y;
C = (C * ((x * inv[y])%mod))%mod;
}
}
}
for(int j = 0 ; j < m ; j ++)dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
ans = (ans + dp[i][m-1])%mod;
}
cout << ans;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4312 KB |
Output is correct |
4 |
Correct |
8 ms |
4316 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
9 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4316 KB |
Output is correct |
8 |
Correct |
8 ms |
4316 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4264 KB |
Output is correct |
13 |
Correct |
8 ms |
4316 KB |
Output is correct |
14 |
Correct |
8 ms |
4316 KB |
Output is correct |
15 |
Correct |
8 ms |
4228 KB |
Output is correct |
16 |
Correct |
4 ms |
2636 KB |
Output is correct |
17 |
Correct |
4 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2636 KB |
Output is correct |
19 |
Correct |
4 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4312 KB |
Output is correct |
4 |
Correct |
8 ms |
4316 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
9 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4316 KB |
Output is correct |
8 |
Correct |
8 ms |
4316 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4264 KB |
Output is correct |
13 |
Correct |
8 ms |
4316 KB |
Output is correct |
14 |
Correct |
8 ms |
4316 KB |
Output is correct |
15 |
Correct |
8 ms |
4228 KB |
Output is correct |
16 |
Correct |
4 ms |
2636 KB |
Output is correct |
17 |
Correct |
4 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2636 KB |
Output is correct |
19 |
Correct |
4 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
330 ms |
4128 KB |
Output is correct |
22 |
Correct |
331 ms |
4088 KB |
Output is correct |
23 |
Correct |
298 ms |
4044 KB |
Output is correct |
24 |
Correct |
350 ms |
3996 KB |
Output is correct |
25 |
Correct |
316 ms |
4284 KB |
Output is correct |
26 |
Correct |
490 ms |
4012 KB |
Output is correct |
27 |
Correct |
500 ms |
4036 KB |
Output is correct |
28 |
Correct |
492 ms |
4036 KB |
Output is correct |
29 |
Correct |
523 ms |
4036 KB |
Output is correct |
30 |
Correct |
9 ms |
4304 KB |
Output is correct |
31 |
Correct |
9 ms |
4300 KB |
Output is correct |
32 |
Correct |
9 ms |
4304 KB |
Output is correct |
33 |
Correct |
9 ms |
4300 KB |
Output is correct |
34 |
Correct |
9 ms |
4300 KB |
Output is correct |
35 |
Correct |
10 ms |
4428 KB |
Output is correct |
36 |
Correct |
11 ms |
4284 KB |
Output is correct |
37 |
Correct |
10 ms |
4208 KB |
Output is correct |
38 |
Correct |
10 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
716 KB |
Output is correct |
2 |
Correct |
4 ms |
716 KB |
Output is correct |
3 |
Correct |
4 ms |
716 KB |
Output is correct |
4 |
Correct |
4 ms |
716 KB |
Output is correct |
5 |
Correct |
4 ms |
716 KB |
Output is correct |
6 |
Correct |
6 ms |
716 KB |
Output is correct |
7 |
Correct |
6 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
6 ms |
716 KB |
Output is correct |
10 |
Correct |
6 ms |
716 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
716 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
3 ms |
716 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
3 ms |
716 KB |
Output is correct |
20 |
Correct |
3 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4312 KB |
Output is correct |
4 |
Correct |
8 ms |
4316 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
9 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4316 KB |
Output is correct |
8 |
Correct |
8 ms |
4316 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4264 KB |
Output is correct |
13 |
Correct |
8 ms |
4316 KB |
Output is correct |
14 |
Correct |
8 ms |
4316 KB |
Output is correct |
15 |
Correct |
8 ms |
4228 KB |
Output is correct |
16 |
Correct |
4 ms |
2636 KB |
Output is correct |
17 |
Correct |
4 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2636 KB |
Output is correct |
19 |
Correct |
4 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
330 ms |
4128 KB |
Output is correct |
22 |
Correct |
331 ms |
4088 KB |
Output is correct |
23 |
Correct |
298 ms |
4044 KB |
Output is correct |
24 |
Correct |
350 ms |
3996 KB |
Output is correct |
25 |
Correct |
316 ms |
4284 KB |
Output is correct |
26 |
Correct |
490 ms |
4012 KB |
Output is correct |
27 |
Correct |
500 ms |
4036 KB |
Output is correct |
28 |
Correct |
492 ms |
4036 KB |
Output is correct |
29 |
Correct |
523 ms |
4036 KB |
Output is correct |
30 |
Correct |
9 ms |
4304 KB |
Output is correct |
31 |
Correct |
9 ms |
4300 KB |
Output is correct |
32 |
Correct |
9 ms |
4304 KB |
Output is correct |
33 |
Correct |
9 ms |
4300 KB |
Output is correct |
34 |
Correct |
9 ms |
4300 KB |
Output is correct |
35 |
Correct |
10 ms |
4428 KB |
Output is correct |
36 |
Correct |
11 ms |
4284 KB |
Output is correct |
37 |
Correct |
10 ms |
4208 KB |
Output is correct |
38 |
Correct |
10 ms |
4300 KB |
Output is correct |
39 |
Correct |
4 ms |
716 KB |
Output is correct |
40 |
Correct |
4 ms |
716 KB |
Output is correct |
41 |
Correct |
4 ms |
716 KB |
Output is correct |
42 |
Correct |
4 ms |
716 KB |
Output is correct |
43 |
Correct |
4 ms |
716 KB |
Output is correct |
44 |
Correct |
6 ms |
716 KB |
Output is correct |
45 |
Correct |
6 ms |
716 KB |
Output is correct |
46 |
Correct |
6 ms |
716 KB |
Output is correct |
47 |
Correct |
6 ms |
716 KB |
Output is correct |
48 |
Correct |
6 ms |
716 KB |
Output is correct |
49 |
Correct |
4 ms |
716 KB |
Output is correct |
50 |
Correct |
3 ms |
716 KB |
Output is correct |
51 |
Correct |
4 ms |
716 KB |
Output is correct |
52 |
Correct |
3 ms |
716 KB |
Output is correct |
53 |
Correct |
4 ms |
716 KB |
Output is correct |
54 |
Correct |
3 ms |
716 KB |
Output is correct |
55 |
Correct |
3 ms |
716 KB |
Output is correct |
56 |
Correct |
3 ms |
716 KB |
Output is correct |
57 |
Correct |
3 ms |
716 KB |
Output is correct |
58 |
Correct |
3 ms |
720 KB |
Output is correct |
59 |
Correct |
357 ms |
4236 KB |
Output is correct |
60 |
Correct |
342 ms |
4192 KB |
Output is correct |
61 |
Correct |
315 ms |
4192 KB |
Output is correct |
62 |
Correct |
365 ms |
4308 KB |
Output is correct |
63 |
Correct |
345 ms |
4292 KB |
Output is correct |
64 |
Correct |
562 ms |
4372 KB |
Output is correct |
65 |
Correct |
569 ms |
4244 KB |
Output is correct |
66 |
Correct |
579 ms |
4388 KB |
Output is correct |
67 |
Correct |
560 ms |
4320 KB |
Output is correct |
68 |
Correct |
576 ms |
4356 KB |
Output is correct |
69 |
Correct |
280 ms |
4292 KB |
Output is correct |
70 |
Correct |
277 ms |
4332 KB |
Output is correct |
71 |
Correct |
277 ms |
4296 KB |
Output is correct |
72 |
Correct |
291 ms |
4292 KB |
Output is correct |
73 |
Correct |
292 ms |
4200 KB |
Output is correct |
74 |
Correct |
74 ms |
2696 KB |
Output is correct |
75 |
Correct |
70 ms |
2632 KB |
Output is correct |
76 |
Correct |
76 ms |
2772 KB |
Output is correct |
77 |
Correct |
75 ms |
2632 KB |
Output is correct |
78 |
Correct |
75 ms |
2692 KB |
Output is correct |