#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("FEEDING.INP");
ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7, inf = 1e16;
const int mxn = 3e5 + 5;
int n;
ll l[505], r[505], inv[505], dp[1005][505];
ll pw(ll a, ll b){
ll res = 1;
for(;b;b >>= 1){
if(b & 1){
res = (res * a) % mod;
}
a = (a * a) % mod;
}
return(res);
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
vt<int>comp;
for(int i = 1; i <= n; i++){
cin >> l[i] >> r[i];
inv[i] = pw(i, mod - 2);
comp.pb(l[i]); comp.pb(r[i] + 1);
}
comp.pb(0);
sort(comp.begin(), comp.end()); comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
for(int i = 0; i <= n; i++){
dp[0][i] = 1;
}
for(int i = 1; i < sz(comp) - 1; i++){
for(int j = 0; j <= n; j++){
dp[i][j] = dp[i - 1][j];
ll ways = 1, cnt = 0;
for(int k = j; k >= 1; k--){
if(l[k] <= comp[i] && comp[i + 1] - 1 <= r[k]){
cnt++;
ll sus = ((comp[i + 1] - comp[i] + cnt - 1) * inv[cnt]) % mod;
ways = (ways * sus) % mod;
//cout << sus << " ";
dp[i][j] = (dp[i][j] + dp[i - 1][k - 1] * ways) % mod;
}
}
}
}
cout << (dp[sz(comp) - 2][n] - 1 + mod) % mod;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
4188 KB |
Output is correct |
2 |
Correct |
158 ms |
4228 KB |
Output is correct |
3 |
Correct |
164 ms |
4304 KB |
Output is correct |
4 |
Correct |
163 ms |
4188 KB |
Output is correct |
5 |
Correct |
162 ms |
4288 KB |
Output is correct |
6 |
Correct |
133 ms |
4220 KB |
Output is correct |
7 |
Correct |
145 ms |
4284 KB |
Output is correct |
8 |
Correct |
133 ms |
4224 KB |
Output is correct |
9 |
Correct |
130 ms |
4192 KB |
Output is correct |
10 |
Correct |
128 ms |
4232 KB |
Output is correct |
11 |
Correct |
131 ms |
4280 KB |
Output is correct |
12 |
Correct |
144 ms |
4180 KB |
Output is correct |
13 |
Correct |
134 ms |
4212 KB |
Output is correct |
14 |
Correct |
124 ms |
4200 KB |
Output is correct |
15 |
Correct |
149 ms |
4232 KB |
Output is correct |
16 |
Correct |
29 ms |
972 KB |
Output is correct |
17 |
Correct |
34 ms |
1080 KB |
Output is correct |
18 |
Correct |
30 ms |
984 KB |
Output is correct |
19 |
Correct |
31 ms |
972 KB |
Output is correct |
20 |
Correct |
31 ms |
1028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
4188 KB |
Output is correct |
2 |
Correct |
158 ms |
4228 KB |
Output is correct |
3 |
Correct |
164 ms |
4304 KB |
Output is correct |
4 |
Correct |
163 ms |
4188 KB |
Output is correct |
5 |
Correct |
162 ms |
4288 KB |
Output is correct |
6 |
Correct |
133 ms |
4220 KB |
Output is correct |
7 |
Correct |
145 ms |
4284 KB |
Output is correct |
8 |
Correct |
133 ms |
4224 KB |
Output is correct |
9 |
Correct |
130 ms |
4192 KB |
Output is correct |
10 |
Correct |
128 ms |
4232 KB |
Output is correct |
11 |
Correct |
131 ms |
4280 KB |
Output is correct |
12 |
Correct |
144 ms |
4180 KB |
Output is correct |
13 |
Correct |
134 ms |
4212 KB |
Output is correct |
14 |
Correct |
124 ms |
4200 KB |
Output is correct |
15 |
Correct |
149 ms |
4232 KB |
Output is correct |
16 |
Correct |
29 ms |
972 KB |
Output is correct |
17 |
Correct |
34 ms |
1080 KB |
Output is correct |
18 |
Correct |
30 ms |
984 KB |
Output is correct |
19 |
Correct |
31 ms |
972 KB |
Output is correct |
20 |
Correct |
31 ms |
1028 KB |
Output is correct |
21 |
Correct |
297 ms |
3880 KB |
Output is correct |
22 |
Correct |
305 ms |
3996 KB |
Output is correct |
23 |
Correct |
348 ms |
3832 KB |
Output is correct |
24 |
Correct |
309 ms |
3876 KB |
Output is correct |
25 |
Correct |
330 ms |
3832 KB |
Output is correct |
26 |
Correct |
413 ms |
3832 KB |
Output is correct |
27 |
Correct |
395 ms |
3788 KB |
Output is correct |
28 |
Correct |
389 ms |
3860 KB |
Output is correct |
29 |
Correct |
390 ms |
3788 KB |
Output is correct |
30 |
Correct |
133 ms |
4168 KB |
Output is correct |
31 |
Correct |
129 ms |
4228 KB |
Output is correct |
32 |
Correct |
128 ms |
4252 KB |
Output is correct |
33 |
Correct |
127 ms |
4296 KB |
Output is correct |
34 |
Correct |
129 ms |
4172 KB |
Output is correct |
35 |
Correct |
167 ms |
4180 KB |
Output is correct |
36 |
Correct |
160 ms |
4264 KB |
Output is correct |
37 |
Correct |
158 ms |
4168 KB |
Output is correct |
38 |
Correct |
161 ms |
4232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
4 ms |
1108 KB |
Output is correct |
4 |
Correct |
3 ms |
1108 KB |
Output is correct |
5 |
Correct |
4 ms |
1108 KB |
Output is correct |
6 |
Correct |
4 ms |
1108 KB |
Output is correct |
7 |
Correct |
4 ms |
1108 KB |
Output is correct |
8 |
Correct |
4 ms |
1108 KB |
Output is correct |
9 |
Correct |
5 ms |
1108 KB |
Output is correct |
10 |
Correct |
5 ms |
1108 KB |
Output is correct |
11 |
Correct |
4 ms |
1068 KB |
Output is correct |
12 |
Correct |
4 ms |
1108 KB |
Output is correct |
13 |
Correct |
4 ms |
1108 KB |
Output is correct |
14 |
Correct |
4 ms |
1108 KB |
Output is correct |
15 |
Correct |
4 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
4188 KB |
Output is correct |
2 |
Correct |
158 ms |
4228 KB |
Output is correct |
3 |
Correct |
164 ms |
4304 KB |
Output is correct |
4 |
Correct |
163 ms |
4188 KB |
Output is correct |
5 |
Correct |
162 ms |
4288 KB |
Output is correct |
6 |
Correct |
133 ms |
4220 KB |
Output is correct |
7 |
Correct |
145 ms |
4284 KB |
Output is correct |
8 |
Correct |
133 ms |
4224 KB |
Output is correct |
9 |
Correct |
130 ms |
4192 KB |
Output is correct |
10 |
Correct |
128 ms |
4232 KB |
Output is correct |
11 |
Correct |
131 ms |
4280 KB |
Output is correct |
12 |
Correct |
144 ms |
4180 KB |
Output is correct |
13 |
Correct |
134 ms |
4212 KB |
Output is correct |
14 |
Correct |
124 ms |
4200 KB |
Output is correct |
15 |
Correct |
149 ms |
4232 KB |
Output is correct |
16 |
Correct |
29 ms |
972 KB |
Output is correct |
17 |
Correct |
34 ms |
1080 KB |
Output is correct |
18 |
Correct |
30 ms |
984 KB |
Output is correct |
19 |
Correct |
31 ms |
972 KB |
Output is correct |
20 |
Correct |
31 ms |
1028 KB |
Output is correct |
21 |
Correct |
297 ms |
3880 KB |
Output is correct |
22 |
Correct |
305 ms |
3996 KB |
Output is correct |
23 |
Correct |
348 ms |
3832 KB |
Output is correct |
24 |
Correct |
309 ms |
3876 KB |
Output is correct |
25 |
Correct |
330 ms |
3832 KB |
Output is correct |
26 |
Correct |
413 ms |
3832 KB |
Output is correct |
27 |
Correct |
395 ms |
3788 KB |
Output is correct |
28 |
Correct |
389 ms |
3860 KB |
Output is correct |
29 |
Correct |
390 ms |
3788 KB |
Output is correct |
30 |
Correct |
133 ms |
4168 KB |
Output is correct |
31 |
Correct |
129 ms |
4228 KB |
Output is correct |
32 |
Correct |
128 ms |
4252 KB |
Output is correct |
33 |
Correct |
127 ms |
4296 KB |
Output is correct |
34 |
Correct |
129 ms |
4172 KB |
Output is correct |
35 |
Correct |
167 ms |
4180 KB |
Output is correct |
36 |
Correct |
160 ms |
4264 KB |
Output is correct |
37 |
Correct |
158 ms |
4168 KB |
Output is correct |
38 |
Correct |
161 ms |
4232 KB |
Output is correct |
39 |
Correct |
4 ms |
1108 KB |
Output is correct |
40 |
Correct |
3 ms |
1108 KB |
Output is correct |
41 |
Correct |
4 ms |
1108 KB |
Output is correct |
42 |
Correct |
3 ms |
1108 KB |
Output is correct |
43 |
Correct |
4 ms |
1108 KB |
Output is correct |
44 |
Correct |
4 ms |
1108 KB |
Output is correct |
45 |
Correct |
4 ms |
1108 KB |
Output is correct |
46 |
Correct |
4 ms |
1108 KB |
Output is correct |
47 |
Correct |
5 ms |
1108 KB |
Output is correct |
48 |
Correct |
5 ms |
1108 KB |
Output is correct |
49 |
Correct |
4 ms |
1068 KB |
Output is correct |
50 |
Correct |
4 ms |
1108 KB |
Output is correct |
51 |
Correct |
4 ms |
1108 KB |
Output is correct |
52 |
Correct |
4 ms |
1108 KB |
Output is correct |
53 |
Correct |
4 ms |
1108 KB |
Output is correct |
54 |
Correct |
2 ms |
724 KB |
Output is correct |
55 |
Correct |
2 ms |
724 KB |
Output is correct |
56 |
Correct |
2 ms |
724 KB |
Output is correct |
57 |
Correct |
2 ms |
724 KB |
Output is correct |
58 |
Correct |
2 ms |
724 KB |
Output is correct |
59 |
Correct |
328 ms |
4216 KB |
Output is correct |
60 |
Correct |
313 ms |
4288 KB |
Output is correct |
61 |
Correct |
315 ms |
4356 KB |
Output is correct |
62 |
Correct |
331 ms |
4288 KB |
Output is correct |
63 |
Correct |
317 ms |
4212 KB |
Output is correct |
64 |
Correct |
453 ms |
4220 KB |
Output is correct |
65 |
Correct |
444 ms |
4340 KB |
Output is correct |
66 |
Correct |
449 ms |
4256 KB |
Output is correct |
67 |
Correct |
453 ms |
4428 KB |
Output is correct |
68 |
Correct |
460 ms |
4288 KB |
Output is correct |
69 |
Correct |
361 ms |
4312 KB |
Output is correct |
70 |
Correct |
378 ms |
4236 KB |
Output is correct |
71 |
Correct |
365 ms |
4272 KB |
Output is correct |
72 |
Correct |
391 ms |
4204 KB |
Output is correct |
73 |
Correct |
367 ms |
4304 KB |
Output is correct |
74 |
Correct |
62 ms |
1016 KB |
Output is correct |
75 |
Correct |
66 ms |
972 KB |
Output is correct |
76 |
Correct |
64 ms |
1044 KB |
Output is correct |
77 |
Correct |
68 ms |
1076 KB |
Output is correct |
78 |
Correct |
64 ms |
984 KB |
Output is correct |