#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 505, mod = 1e9 + 7; // !
int t, L[N], R[N], n, dp[ N][4 *N],fact[N], invfact[N], c[N][N], cc[N], p[N];
vector<int> x;
int pwr(int u,int v) {
int ans = 1;
while(v) {
if(v % 2) ans = (ll)u * ans % mod;
v /= 2; u = (ll)u * u % mod;
}
return ans;
}
int C(int a,int b) {
if(a < b) return 0;
int x = 1;
for(int j = a - b + 1; j <= a; j++) x = (ll)x * j % mod;
return (ll)x * invfact[b] % mod;
}
int C2(int a,int b) {
if(a < b) return 0;
return (ll)fact[a] * invfact[a - b] % mod * invfact[b] % mod;
}
void go(int i,int l, int r) {
for(int j = 0; j <= n; j++) cc[j] = C(r - l + 1, j);
for(int len = 1; len <= n; len++) {
for(int x = 1; x <= len; x++) c[len][x] = ((ll)cc[x] * C2(len - 1, x - 1) % mod + c[len][x - 1]) % mod;
}
for(int j = 1; j <= n; j++) {
p[j] = p[j - 1];
if(L[j] <= l && r <= R[j]) p[j]++;
if(!(p[j] - p[j - 1])) continue;
for(int k = 0; k < j; k++) {
dp[j][i] += (ll)dp[k][i - 1] * c[p[j] - p[k]][p[j] - p[k]] % mod;
if(dp[j][i] >= mod) dp[j][i] -= mod;
}
}
for(int j = 0; j <= n; j++) {
dp[j][i] += dp[j][i - 1];
if(dp[j][i] >= mod) dp[j][i] -= mod;
}
}
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n;
fact[0] = invfact[0] = 1;
for(int i = 1; i <= n; i++) {
cin >> L[i] >> R[i];
x.push_back(L[i]);
x.push_back(R[i] + 1);
fact[i] = (ll)fact[i - 1] * i % mod;
invfact[i] = (ll)invfact[i - 1] * pwr(i, mod - 2) % mod;
}
x.push_back(-1);
sort(x.begin(), x.end());
dp[0][0] = 1;
int cur = 0;
for(int i = 1; i < x.size(); i++) {
if(x[i] < x[i + 1]) go(++cur, x[i], x[i + 1] - 1);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + dp[i][cur]) % mod;
}
cout << ans;
}
Compilation message
boat.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main(){
| ^~~~
boat.cpp: In function 'int main()':
boat.cpp:66:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i = 1; i < x.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1300 ms |
5256 KB |
Output is correct |
2 |
Correct |
1297 ms |
5232 KB |
Output is correct |
3 |
Correct |
1305 ms |
5204 KB |
Output is correct |
4 |
Correct |
1319 ms |
5160 KB |
Output is correct |
5 |
Correct |
1342 ms |
5212 KB |
Output is correct |
6 |
Correct |
1322 ms |
5180 KB |
Output is correct |
7 |
Correct |
1350 ms |
5232 KB |
Output is correct |
8 |
Correct |
1337 ms |
5204 KB |
Output is correct |
9 |
Correct |
1384 ms |
5392 KB |
Output is correct |
10 |
Correct |
1342 ms |
5452 KB |
Output is correct |
11 |
Correct |
1344 ms |
5188 KB |
Output is correct |
12 |
Correct |
1381 ms |
5196 KB |
Output is correct |
13 |
Correct |
1302 ms |
5324 KB |
Output is correct |
14 |
Correct |
1319 ms |
5396 KB |
Output is correct |
15 |
Correct |
1303 ms |
5148 KB |
Output is correct |
16 |
Correct |
238 ms |
3600 KB |
Output is correct |
17 |
Correct |
242 ms |
3652 KB |
Output is correct |
18 |
Correct |
238 ms |
3624 KB |
Output is correct |
19 |
Correct |
259 ms |
3884 KB |
Output is correct |
20 |
Correct |
234 ms |
3628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1300 ms |
5256 KB |
Output is correct |
2 |
Correct |
1297 ms |
5232 KB |
Output is correct |
3 |
Correct |
1305 ms |
5204 KB |
Output is correct |
4 |
Correct |
1319 ms |
5160 KB |
Output is correct |
5 |
Correct |
1342 ms |
5212 KB |
Output is correct |
6 |
Correct |
1322 ms |
5180 KB |
Output is correct |
7 |
Correct |
1350 ms |
5232 KB |
Output is correct |
8 |
Correct |
1337 ms |
5204 KB |
Output is correct |
9 |
Correct |
1384 ms |
5392 KB |
Output is correct |
10 |
Correct |
1342 ms |
5452 KB |
Output is correct |
11 |
Correct |
1344 ms |
5188 KB |
Output is correct |
12 |
Correct |
1381 ms |
5196 KB |
Output is correct |
13 |
Correct |
1302 ms |
5324 KB |
Output is correct |
14 |
Correct |
1319 ms |
5396 KB |
Output is correct |
15 |
Correct |
1303 ms |
5148 KB |
Output is correct |
16 |
Correct |
238 ms |
3600 KB |
Output is correct |
17 |
Correct |
242 ms |
3652 KB |
Output is correct |
18 |
Correct |
238 ms |
3624 KB |
Output is correct |
19 |
Correct |
259 ms |
3884 KB |
Output is correct |
20 |
Correct |
234 ms |
3628 KB |
Output is correct |
21 |
Correct |
1036 ms |
5060 KB |
Output is correct |
22 |
Correct |
1052 ms |
5012 KB |
Output is correct |
23 |
Correct |
1035 ms |
5180 KB |
Output is correct |
24 |
Correct |
1036 ms |
5060 KB |
Output is correct |
25 |
Correct |
1067 ms |
4988 KB |
Output is correct |
26 |
Correct |
1146 ms |
4988 KB |
Output is correct |
27 |
Correct |
1113 ms |
4984 KB |
Output is correct |
28 |
Correct |
1065 ms |
5004 KB |
Output is correct |
29 |
Correct |
1055 ms |
4992 KB |
Output is correct |
30 |
Correct |
1244 ms |
5220 KB |
Output is correct |
31 |
Correct |
1232 ms |
5296 KB |
Output is correct |
32 |
Correct |
1242 ms |
5188 KB |
Output is correct |
33 |
Correct |
1248 ms |
5284 KB |
Output is correct |
34 |
Correct |
1251 ms |
5208 KB |
Output is correct |
35 |
Correct |
1231 ms |
5260 KB |
Output is correct |
36 |
Correct |
1233 ms |
5224 KB |
Output is correct |
37 |
Correct |
1256 ms |
5268 KB |
Output is correct |
38 |
Correct |
1236 ms |
5188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
972 KB |
Output is correct |
2 |
Correct |
16 ms |
972 KB |
Output is correct |
3 |
Correct |
14 ms |
972 KB |
Output is correct |
4 |
Correct |
14 ms |
940 KB |
Output is correct |
5 |
Correct |
15 ms |
972 KB |
Output is correct |
6 |
Correct |
15 ms |
972 KB |
Output is correct |
7 |
Correct |
15 ms |
980 KB |
Output is correct |
8 |
Correct |
15 ms |
964 KB |
Output is correct |
9 |
Correct |
15 ms |
984 KB |
Output is correct |
10 |
Correct |
17 ms |
972 KB |
Output is correct |
11 |
Correct |
14 ms |
980 KB |
Output is correct |
12 |
Correct |
14 ms |
996 KB |
Output is correct |
13 |
Correct |
14 ms |
972 KB |
Output is correct |
14 |
Correct |
14 ms |
1008 KB |
Output is correct |
15 |
Correct |
15 ms |
992 KB |
Output is correct |
16 |
Correct |
8 ms |
972 KB |
Output is correct |
17 |
Correct |
8 ms |
972 KB |
Output is correct |
18 |
Correct |
8 ms |
888 KB |
Output is correct |
19 |
Correct |
8 ms |
944 KB |
Output is correct |
20 |
Correct |
8 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1300 ms |
5256 KB |
Output is correct |
2 |
Correct |
1297 ms |
5232 KB |
Output is correct |
3 |
Correct |
1305 ms |
5204 KB |
Output is correct |
4 |
Correct |
1319 ms |
5160 KB |
Output is correct |
5 |
Correct |
1342 ms |
5212 KB |
Output is correct |
6 |
Correct |
1322 ms |
5180 KB |
Output is correct |
7 |
Correct |
1350 ms |
5232 KB |
Output is correct |
8 |
Correct |
1337 ms |
5204 KB |
Output is correct |
9 |
Correct |
1384 ms |
5392 KB |
Output is correct |
10 |
Correct |
1342 ms |
5452 KB |
Output is correct |
11 |
Correct |
1344 ms |
5188 KB |
Output is correct |
12 |
Correct |
1381 ms |
5196 KB |
Output is correct |
13 |
Correct |
1302 ms |
5324 KB |
Output is correct |
14 |
Correct |
1319 ms |
5396 KB |
Output is correct |
15 |
Correct |
1303 ms |
5148 KB |
Output is correct |
16 |
Correct |
238 ms |
3600 KB |
Output is correct |
17 |
Correct |
242 ms |
3652 KB |
Output is correct |
18 |
Correct |
238 ms |
3624 KB |
Output is correct |
19 |
Correct |
259 ms |
3884 KB |
Output is correct |
20 |
Correct |
234 ms |
3628 KB |
Output is correct |
21 |
Correct |
1036 ms |
5060 KB |
Output is correct |
22 |
Correct |
1052 ms |
5012 KB |
Output is correct |
23 |
Correct |
1035 ms |
5180 KB |
Output is correct |
24 |
Correct |
1036 ms |
5060 KB |
Output is correct |
25 |
Correct |
1067 ms |
4988 KB |
Output is correct |
26 |
Correct |
1146 ms |
4988 KB |
Output is correct |
27 |
Correct |
1113 ms |
4984 KB |
Output is correct |
28 |
Correct |
1065 ms |
5004 KB |
Output is correct |
29 |
Correct |
1055 ms |
4992 KB |
Output is correct |
30 |
Correct |
1244 ms |
5220 KB |
Output is correct |
31 |
Correct |
1232 ms |
5296 KB |
Output is correct |
32 |
Correct |
1242 ms |
5188 KB |
Output is correct |
33 |
Correct |
1248 ms |
5284 KB |
Output is correct |
34 |
Correct |
1251 ms |
5208 KB |
Output is correct |
35 |
Correct |
1231 ms |
5260 KB |
Output is correct |
36 |
Correct |
1233 ms |
5224 KB |
Output is correct |
37 |
Correct |
1256 ms |
5268 KB |
Output is correct |
38 |
Correct |
1236 ms |
5188 KB |
Output is correct |
39 |
Correct |
15 ms |
972 KB |
Output is correct |
40 |
Correct |
16 ms |
972 KB |
Output is correct |
41 |
Correct |
14 ms |
972 KB |
Output is correct |
42 |
Correct |
14 ms |
940 KB |
Output is correct |
43 |
Correct |
15 ms |
972 KB |
Output is correct |
44 |
Correct |
15 ms |
972 KB |
Output is correct |
45 |
Correct |
15 ms |
980 KB |
Output is correct |
46 |
Correct |
15 ms |
964 KB |
Output is correct |
47 |
Correct |
15 ms |
984 KB |
Output is correct |
48 |
Correct |
17 ms |
972 KB |
Output is correct |
49 |
Correct |
14 ms |
980 KB |
Output is correct |
50 |
Correct |
14 ms |
996 KB |
Output is correct |
51 |
Correct |
14 ms |
972 KB |
Output is correct |
52 |
Correct |
14 ms |
1008 KB |
Output is correct |
53 |
Correct |
15 ms |
992 KB |
Output is correct |
54 |
Correct |
8 ms |
972 KB |
Output is correct |
55 |
Correct |
8 ms |
972 KB |
Output is correct |
56 |
Correct |
8 ms |
888 KB |
Output is correct |
57 |
Correct |
8 ms |
944 KB |
Output is correct |
58 |
Correct |
8 ms |
972 KB |
Output is correct |
59 |
Correct |
1733 ms |
5276 KB |
Output is correct |
60 |
Correct |
1763 ms |
5236 KB |
Output is correct |
61 |
Correct |
1732 ms |
5232 KB |
Output is correct |
62 |
Correct |
1740 ms |
5256 KB |
Output is correct |
63 |
Correct |
1727 ms |
5340 KB |
Output is correct |
64 |
Correct |
1806 ms |
5368 KB |
Output is correct |
65 |
Correct |
1826 ms |
5348 KB |
Output is correct |
66 |
Correct |
1825 ms |
5272 KB |
Output is correct |
67 |
Correct |
1833 ms |
5380 KB |
Output is correct |
68 |
Correct |
1838 ms |
5412 KB |
Output is correct |
69 |
Correct |
1762 ms |
5168 KB |
Output is correct |
70 |
Correct |
1711 ms |
5244 KB |
Output is correct |
71 |
Correct |
1748 ms |
5252 KB |
Output is correct |
72 |
Correct |
1745 ms |
5440 KB |
Output is correct |
73 |
Correct |
1737 ms |
5416 KB |
Output is correct |
74 |
Correct |
274 ms |
3652 KB |
Output is correct |
75 |
Correct |
276 ms |
3636 KB |
Output is correct |
76 |
Correct |
281 ms |
3708 KB |
Output is correct |
77 |
Correct |
274 ms |
3652 KB |
Output is correct |
78 |
Correct |
276 ms |
3580 KB |
Output is correct |