#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
void upd(ll& a, const ll& b) { a = (a + b) % mod; }
ll mul(const ll& a, const ll& b)
{
return (a * b) % mod;
}
ll pwr(const ll& a, const ll& b)
{
if (!b) return 1;
ll h = pwr(a, b >> 1);
h = mul(h, h);
if (b & 1) h = mul(h, a);
return h;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
set<int>s(a.begin(), a.end());
for (int i = 0; i <= n; i++) s.insert(b[i] + 1);
vector<int> v(s.begin(), s.end());
vector<vector<ll>> c(v.size(), vector<ll>(n + 1, 0));
for (int i = 0; i < v.size() - 1; i++)
{
int len = v[i + 1] - v[i];
c[i][0] = 1;
for (int j = 1; j <= min(n, len); j++)
c[i][j] = mul(c[i][j - 1], mul(len - j + 1, pwr(j, mod - 2)));
}
vector<vector<ll> > dp(v.size(), vector<ll>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
{
ll sum = 0;
for (int s = 0; s < v.size() - 1; s++)
{
ll sum2 = 0;
// ukoncime tuto uroven
for (int pick = 0; pick < i; pick++) upd(sum2, mul(dp[s][pick], c[s][pick]));
if (a[i] <= v[s] && v[s] <= b[i])
{
for (int pick = i - 1; pick > 0; pick--)
upd(dp[s][pick + 1], dp[s][pick]);
upd(dp[s][1], sum);
}
upd(sum, sum2);
}
/*for (int s = 0; s < v.size() - 1; s++)
{
cout << v[s] << ": ";
for (int p = 0; p <= i; p++) cout << dp[s][p] << " ";
cout << "\n";
}
cout << "\n";*/
}
ll ans = 0;
for (int i = 0; i < v.size(); i++)
for (int j = 1; j <= n; j++)
upd(ans, mul(dp[i][j], c[i][j]));
cout << ans << "\n";
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < v.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
boat.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int s = 0; s < v.size() - 1; s++)
| ~~^~~~~~~~~~~~~~
boat.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
709 ms |
8288 KB |
Output is correct |
2 |
Correct |
732 ms |
8288 KB |
Output is correct |
3 |
Correct |
723 ms |
8260 KB |
Output is correct |
4 |
Correct |
712 ms |
8284 KB |
Output is correct |
5 |
Correct |
711 ms |
8284 KB |
Output is correct |
6 |
Correct |
705 ms |
8284 KB |
Output is correct |
7 |
Correct |
706 ms |
8260 KB |
Output is correct |
8 |
Correct |
718 ms |
8164 KB |
Output is correct |
9 |
Correct |
719 ms |
8388 KB |
Output is correct |
10 |
Correct |
706 ms |
8284 KB |
Output is correct |
11 |
Correct |
700 ms |
8288 KB |
Output is correct |
12 |
Correct |
703 ms |
8172 KB |
Output is correct |
13 |
Correct |
705 ms |
8284 KB |
Output is correct |
14 |
Correct |
738 ms |
8380 KB |
Output is correct |
15 |
Correct |
705 ms |
8288 KB |
Output is correct |
16 |
Correct |
119 ms |
1740 KB |
Output is correct |
17 |
Correct |
130 ms |
1836 KB |
Output is correct |
18 |
Correct |
125 ms |
1740 KB |
Output is correct |
19 |
Correct |
128 ms |
1740 KB |
Output is correct |
20 |
Correct |
125 ms |
1788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
709 ms |
8288 KB |
Output is correct |
2 |
Correct |
732 ms |
8288 KB |
Output is correct |
3 |
Correct |
723 ms |
8260 KB |
Output is correct |
4 |
Correct |
712 ms |
8284 KB |
Output is correct |
5 |
Correct |
711 ms |
8284 KB |
Output is correct |
6 |
Correct |
705 ms |
8284 KB |
Output is correct |
7 |
Correct |
706 ms |
8260 KB |
Output is correct |
8 |
Correct |
718 ms |
8164 KB |
Output is correct |
9 |
Correct |
719 ms |
8388 KB |
Output is correct |
10 |
Correct |
706 ms |
8284 KB |
Output is correct |
11 |
Correct |
700 ms |
8288 KB |
Output is correct |
12 |
Correct |
703 ms |
8172 KB |
Output is correct |
13 |
Correct |
705 ms |
8284 KB |
Output is correct |
14 |
Correct |
738 ms |
8380 KB |
Output is correct |
15 |
Correct |
705 ms |
8288 KB |
Output is correct |
16 |
Correct |
119 ms |
1740 KB |
Output is correct |
17 |
Correct |
130 ms |
1836 KB |
Output is correct |
18 |
Correct |
125 ms |
1740 KB |
Output is correct |
19 |
Correct |
128 ms |
1740 KB |
Output is correct |
20 |
Correct |
125 ms |
1788 KB |
Output is correct |
21 |
Correct |
658 ms |
7588 KB |
Output is correct |
22 |
Correct |
664 ms |
7668 KB |
Output is correct |
23 |
Correct |
630 ms |
7552 KB |
Output is correct |
24 |
Correct |
638 ms |
7500 KB |
Output is correct |
25 |
Correct |
642 ms |
7620 KB |
Output is correct |
26 |
Correct |
667 ms |
7328 KB |
Output is correct |
27 |
Correct |
681 ms |
7444 KB |
Output is correct |
28 |
Correct |
656 ms |
7228 KB |
Output is correct |
29 |
Correct |
644 ms |
7244 KB |
Output is correct |
30 |
Correct |
716 ms |
8264 KB |
Output is correct |
31 |
Correct |
725 ms |
8276 KB |
Output is correct |
32 |
Correct |
705 ms |
8264 KB |
Output is correct |
33 |
Correct |
705 ms |
8284 KB |
Output is correct |
34 |
Correct |
696 ms |
8156 KB |
Output is correct |
35 |
Correct |
712 ms |
8260 KB |
Output is correct |
36 |
Correct |
732 ms |
8260 KB |
Output is correct |
37 |
Correct |
703 ms |
8268 KB |
Output is correct |
38 |
Correct |
698 ms |
8252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
588 KB |
Output is correct |
2 |
Correct |
13 ms |
664 KB |
Output is correct |
3 |
Correct |
13 ms |
588 KB |
Output is correct |
4 |
Correct |
13 ms |
660 KB |
Output is correct |
5 |
Correct |
13 ms |
620 KB |
Output is correct |
6 |
Correct |
15 ms |
588 KB |
Output is correct |
7 |
Correct |
13 ms |
592 KB |
Output is correct |
8 |
Correct |
13 ms |
588 KB |
Output is correct |
9 |
Correct |
14 ms |
588 KB |
Output is correct |
10 |
Correct |
13 ms |
560 KB |
Output is correct |
11 |
Correct |
13 ms |
660 KB |
Output is correct |
12 |
Correct |
13 ms |
660 KB |
Output is correct |
13 |
Correct |
13 ms |
616 KB |
Output is correct |
14 |
Correct |
14 ms |
660 KB |
Output is correct |
15 |
Correct |
14 ms |
632 KB |
Output is correct |
16 |
Correct |
7 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
460 KB |
Output is correct |
18 |
Correct |
8 ms |
460 KB |
Output is correct |
19 |
Correct |
9 ms |
420 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
709 ms |
8288 KB |
Output is correct |
2 |
Correct |
732 ms |
8288 KB |
Output is correct |
3 |
Correct |
723 ms |
8260 KB |
Output is correct |
4 |
Correct |
712 ms |
8284 KB |
Output is correct |
5 |
Correct |
711 ms |
8284 KB |
Output is correct |
6 |
Correct |
705 ms |
8284 KB |
Output is correct |
7 |
Correct |
706 ms |
8260 KB |
Output is correct |
8 |
Correct |
718 ms |
8164 KB |
Output is correct |
9 |
Correct |
719 ms |
8388 KB |
Output is correct |
10 |
Correct |
706 ms |
8284 KB |
Output is correct |
11 |
Correct |
700 ms |
8288 KB |
Output is correct |
12 |
Correct |
703 ms |
8172 KB |
Output is correct |
13 |
Correct |
705 ms |
8284 KB |
Output is correct |
14 |
Correct |
738 ms |
8380 KB |
Output is correct |
15 |
Correct |
705 ms |
8288 KB |
Output is correct |
16 |
Correct |
119 ms |
1740 KB |
Output is correct |
17 |
Correct |
130 ms |
1836 KB |
Output is correct |
18 |
Correct |
125 ms |
1740 KB |
Output is correct |
19 |
Correct |
128 ms |
1740 KB |
Output is correct |
20 |
Correct |
125 ms |
1788 KB |
Output is correct |
21 |
Correct |
658 ms |
7588 KB |
Output is correct |
22 |
Correct |
664 ms |
7668 KB |
Output is correct |
23 |
Correct |
630 ms |
7552 KB |
Output is correct |
24 |
Correct |
638 ms |
7500 KB |
Output is correct |
25 |
Correct |
642 ms |
7620 KB |
Output is correct |
26 |
Correct |
667 ms |
7328 KB |
Output is correct |
27 |
Correct |
681 ms |
7444 KB |
Output is correct |
28 |
Correct |
656 ms |
7228 KB |
Output is correct |
29 |
Correct |
644 ms |
7244 KB |
Output is correct |
30 |
Correct |
716 ms |
8264 KB |
Output is correct |
31 |
Correct |
725 ms |
8276 KB |
Output is correct |
32 |
Correct |
705 ms |
8264 KB |
Output is correct |
33 |
Correct |
705 ms |
8284 KB |
Output is correct |
34 |
Correct |
696 ms |
8156 KB |
Output is correct |
35 |
Correct |
712 ms |
8260 KB |
Output is correct |
36 |
Correct |
732 ms |
8260 KB |
Output is correct |
37 |
Correct |
703 ms |
8268 KB |
Output is correct |
38 |
Correct |
698 ms |
8252 KB |
Output is correct |
39 |
Correct |
13 ms |
588 KB |
Output is correct |
40 |
Correct |
13 ms |
664 KB |
Output is correct |
41 |
Correct |
13 ms |
588 KB |
Output is correct |
42 |
Correct |
13 ms |
660 KB |
Output is correct |
43 |
Correct |
13 ms |
620 KB |
Output is correct |
44 |
Correct |
15 ms |
588 KB |
Output is correct |
45 |
Correct |
13 ms |
592 KB |
Output is correct |
46 |
Correct |
13 ms |
588 KB |
Output is correct |
47 |
Correct |
14 ms |
588 KB |
Output is correct |
48 |
Correct |
13 ms |
560 KB |
Output is correct |
49 |
Correct |
13 ms |
660 KB |
Output is correct |
50 |
Correct |
13 ms |
660 KB |
Output is correct |
51 |
Correct |
13 ms |
616 KB |
Output is correct |
52 |
Correct |
14 ms |
660 KB |
Output is correct |
53 |
Correct |
14 ms |
632 KB |
Output is correct |
54 |
Correct |
7 ms |
460 KB |
Output is correct |
55 |
Correct |
7 ms |
460 KB |
Output is correct |
56 |
Correct |
8 ms |
460 KB |
Output is correct |
57 |
Correct |
9 ms |
420 KB |
Output is correct |
58 |
Correct |
7 ms |
512 KB |
Output is correct |
59 |
Correct |
881 ms |
8192 KB |
Output is correct |
60 |
Correct |
898 ms |
8288 KB |
Output is correct |
61 |
Correct |
916 ms |
8292 KB |
Output is correct |
62 |
Correct |
895 ms |
8284 KB |
Output is correct |
63 |
Correct |
863 ms |
8288 KB |
Output is correct |
64 |
Correct |
899 ms |
8288 KB |
Output is correct |
65 |
Correct |
918 ms |
8288 KB |
Output is correct |
66 |
Correct |
925 ms |
8288 KB |
Output is correct |
67 |
Correct |
964 ms |
8288 KB |
Output is correct |
68 |
Correct |
1050 ms |
8292 KB |
Output is correct |
69 |
Correct |
931 ms |
8184 KB |
Output is correct |
70 |
Correct |
882 ms |
8284 KB |
Output is correct |
71 |
Correct |
869 ms |
8172 KB |
Output is correct |
72 |
Correct |
940 ms |
8292 KB |
Output is correct |
73 |
Correct |
876 ms |
8288 KB |
Output is correct |
74 |
Correct |
139 ms |
1768 KB |
Output is correct |
75 |
Correct |
143 ms |
1812 KB |
Output is correct |
76 |
Correct |
144 ms |
1812 KB |
Output is correct |
77 |
Correct |
158 ms |
1736 KB |
Output is correct |
78 |
Correct |
140 ms |
1716 KB |
Output is correct |