///
/// ♪ Pizza mozzarella rella rella rella... ♪
///
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = (l); x < (r); ++x)
#define LoopR(x, l, r) for(int x = (r)-1; x >= (l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
typedef std::pair<ll ,ll > pll;
using namespace std;
const int mod = 1e9 + 7;
const int N = 512;
vector<int> cmp;
int l[N], r[N];
int n;
ll dp[N][2*N];
ll dp2[N][N];
ll fct[2*N], fci[2*N];
ll inv[2*N];
ll Inv(ll x){
ll ans = 1;
for(ll y = mod-2; y; y >>= 1){
if(y&1) ans = ans*x % mod;
x = x*x % mod;
}
return ans;
}
int main()
{
FAST;
cin >> n;
inv[0] = fci[0] = fct[0] = 1;
Loop(i,1,2*N) fct[i] = fct[i-1]*i % mod, fci[i] = Inv(fct[i]), inv[i] = Inv(i);
Loop(i,0,n)
{
cin >> l[i] >> r[i];
++r[i];
cmp.push_back(l[i]);
cmp.push_back(r[i]);
}
sort(all(cmp)); cmp.resize(unique(all(cmp))-cmp.begin());
Loop(i,0,2*N) dp[0][i] = 1;
Loop(i,0,n)
{
Loop(j,0,cmp.size()-1)
{
ll m = cmp[j+1] - cmp[j];
ll X = 1;
int k = 0;
LoopR(p,0,i+1)
{
if(r[p] <= cmp[j] || cmp[j+1] <= l[p]) continue;
X = X*(m+k) % mod;
X = X*inv[k+1] % mod;
++k;
dp[i+1][j] = (dp[i+1][j] + X*dp[p][j]) % mod;
}
}
ll sum = 1;
Loop(j,0,cmp.size())
sum += dp[i+1][j],
dp[i+1][j] = sum - dp[i+1][j],
sum %= mod;
}
//Loop(i,0,n+1) {Loop(j,0,cmp.size()) cout << dp[i][j] << ' '; cout << '\n';}
cout << (dp[n][cmp.size()-1]+mod-1)%mod << '\n';
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:8:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define Loop(x, l, r) for(int x = (l); x < (r); ++x)
| ^
boat.cpp:58:9: note: in expansion of macro 'Loop'
58 | Loop(j,0,cmp.size()-1)
| ^~~~
boat.cpp:8:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define Loop(x, l, r) for(int x = (l); x < (r); ++x)
| ^
boat.cpp:74:9: note: in expansion of macro 'Loop'
74 | Loop(j,0,cmp.size())
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
4292 KB |
Output is correct |
2 |
Correct |
269 ms |
4332 KB |
Output is correct |
3 |
Correct |
260 ms |
4308 KB |
Output is correct |
4 |
Correct |
296 ms |
4356 KB |
Output is correct |
5 |
Correct |
258 ms |
4304 KB |
Output is correct |
6 |
Correct |
170 ms |
4260 KB |
Output is correct |
7 |
Correct |
161 ms |
4272 KB |
Output is correct |
8 |
Correct |
169 ms |
4292 KB |
Output is correct |
9 |
Correct |
175 ms |
4320 KB |
Output is correct |
10 |
Correct |
162 ms |
4292 KB |
Output is correct |
11 |
Correct |
163 ms |
4392 KB |
Output is correct |
12 |
Correct |
166 ms |
4296 KB |
Output is correct |
13 |
Correct |
164 ms |
4276 KB |
Output is correct |
14 |
Correct |
155 ms |
4292 KB |
Output is correct |
15 |
Correct |
163 ms |
4320 KB |
Output is correct |
16 |
Correct |
59 ms |
2368 KB |
Output is correct |
17 |
Correct |
55 ms |
2300 KB |
Output is correct |
18 |
Correct |
55 ms |
2256 KB |
Output is correct |
19 |
Correct |
58 ms |
2260 KB |
Output is correct |
20 |
Correct |
59 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
4292 KB |
Output is correct |
2 |
Correct |
269 ms |
4332 KB |
Output is correct |
3 |
Correct |
260 ms |
4308 KB |
Output is correct |
4 |
Correct |
296 ms |
4356 KB |
Output is correct |
5 |
Correct |
258 ms |
4304 KB |
Output is correct |
6 |
Correct |
170 ms |
4260 KB |
Output is correct |
7 |
Correct |
161 ms |
4272 KB |
Output is correct |
8 |
Correct |
169 ms |
4292 KB |
Output is correct |
9 |
Correct |
175 ms |
4320 KB |
Output is correct |
10 |
Correct |
162 ms |
4292 KB |
Output is correct |
11 |
Correct |
163 ms |
4392 KB |
Output is correct |
12 |
Correct |
166 ms |
4296 KB |
Output is correct |
13 |
Correct |
164 ms |
4276 KB |
Output is correct |
14 |
Correct |
155 ms |
4292 KB |
Output is correct |
15 |
Correct |
163 ms |
4320 KB |
Output is correct |
16 |
Correct |
59 ms |
2368 KB |
Output is correct |
17 |
Correct |
55 ms |
2300 KB |
Output is correct |
18 |
Correct |
55 ms |
2256 KB |
Output is correct |
19 |
Correct |
58 ms |
2260 KB |
Output is correct |
20 |
Correct |
59 ms |
2360 KB |
Output is correct |
21 |
Correct |
585 ms |
4356 KB |
Output is correct |
22 |
Correct |
571 ms |
4424 KB |
Output is correct |
23 |
Correct |
544 ms |
4356 KB |
Output is correct |
24 |
Correct |
561 ms |
4428 KB |
Output is correct |
25 |
Correct |
595 ms |
4356 KB |
Output is correct |
26 |
Correct |
732 ms |
4292 KB |
Output is correct |
27 |
Correct |
749 ms |
4412 KB |
Output is correct |
28 |
Correct |
733 ms |
4288 KB |
Output is correct |
29 |
Correct |
736 ms |
4408 KB |
Output is correct |
30 |
Correct |
171 ms |
4296 KB |
Output is correct |
31 |
Correct |
166 ms |
4336 KB |
Output is correct |
32 |
Correct |
162 ms |
4292 KB |
Output is correct |
33 |
Correct |
168 ms |
4400 KB |
Output is correct |
34 |
Correct |
165 ms |
4292 KB |
Output is correct |
35 |
Correct |
274 ms |
4344 KB |
Output is correct |
36 |
Correct |
271 ms |
4380 KB |
Output is correct |
37 |
Correct |
299 ms |
4336 KB |
Output is correct |
38 |
Correct |
268 ms |
4264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
716 KB |
Output is correct |
2 |
Correct |
5 ms |
716 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Correct |
6 ms |
716 KB |
Output is correct |
6 |
Correct |
8 ms |
716 KB |
Output is correct |
7 |
Correct |
8 ms |
716 KB |
Output is correct |
8 |
Correct |
8 ms |
716 KB |
Output is correct |
9 |
Correct |
8 ms |
700 KB |
Output is correct |
10 |
Correct |
8 ms |
716 KB |
Output is correct |
11 |
Correct |
7 ms |
716 KB |
Output is correct |
12 |
Correct |
6 ms |
716 KB |
Output is correct |
13 |
Correct |
7 ms |
672 KB |
Output is correct |
14 |
Correct |
7 ms |
716 KB |
Output is correct |
15 |
Correct |
6 ms |
696 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
716 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
19 |
Correct |
4 ms |
716 KB |
Output is correct |
20 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
4292 KB |
Output is correct |
2 |
Correct |
269 ms |
4332 KB |
Output is correct |
3 |
Correct |
260 ms |
4308 KB |
Output is correct |
4 |
Correct |
296 ms |
4356 KB |
Output is correct |
5 |
Correct |
258 ms |
4304 KB |
Output is correct |
6 |
Correct |
170 ms |
4260 KB |
Output is correct |
7 |
Correct |
161 ms |
4272 KB |
Output is correct |
8 |
Correct |
169 ms |
4292 KB |
Output is correct |
9 |
Correct |
175 ms |
4320 KB |
Output is correct |
10 |
Correct |
162 ms |
4292 KB |
Output is correct |
11 |
Correct |
163 ms |
4392 KB |
Output is correct |
12 |
Correct |
166 ms |
4296 KB |
Output is correct |
13 |
Correct |
164 ms |
4276 KB |
Output is correct |
14 |
Correct |
155 ms |
4292 KB |
Output is correct |
15 |
Correct |
163 ms |
4320 KB |
Output is correct |
16 |
Correct |
59 ms |
2368 KB |
Output is correct |
17 |
Correct |
55 ms |
2300 KB |
Output is correct |
18 |
Correct |
55 ms |
2256 KB |
Output is correct |
19 |
Correct |
58 ms |
2260 KB |
Output is correct |
20 |
Correct |
59 ms |
2360 KB |
Output is correct |
21 |
Correct |
585 ms |
4356 KB |
Output is correct |
22 |
Correct |
571 ms |
4424 KB |
Output is correct |
23 |
Correct |
544 ms |
4356 KB |
Output is correct |
24 |
Correct |
561 ms |
4428 KB |
Output is correct |
25 |
Correct |
595 ms |
4356 KB |
Output is correct |
26 |
Correct |
732 ms |
4292 KB |
Output is correct |
27 |
Correct |
749 ms |
4412 KB |
Output is correct |
28 |
Correct |
733 ms |
4288 KB |
Output is correct |
29 |
Correct |
736 ms |
4408 KB |
Output is correct |
30 |
Correct |
171 ms |
4296 KB |
Output is correct |
31 |
Correct |
166 ms |
4336 KB |
Output is correct |
32 |
Correct |
162 ms |
4292 KB |
Output is correct |
33 |
Correct |
168 ms |
4400 KB |
Output is correct |
34 |
Correct |
165 ms |
4292 KB |
Output is correct |
35 |
Correct |
274 ms |
4344 KB |
Output is correct |
36 |
Correct |
271 ms |
4380 KB |
Output is correct |
37 |
Correct |
299 ms |
4336 KB |
Output is correct |
38 |
Correct |
268 ms |
4264 KB |
Output is correct |
39 |
Correct |
6 ms |
716 KB |
Output is correct |
40 |
Correct |
5 ms |
716 KB |
Output is correct |
41 |
Correct |
6 ms |
716 KB |
Output is correct |
42 |
Correct |
6 ms |
716 KB |
Output is correct |
43 |
Correct |
6 ms |
716 KB |
Output is correct |
44 |
Correct |
8 ms |
716 KB |
Output is correct |
45 |
Correct |
8 ms |
716 KB |
Output is correct |
46 |
Correct |
8 ms |
716 KB |
Output is correct |
47 |
Correct |
8 ms |
700 KB |
Output is correct |
48 |
Correct |
8 ms |
716 KB |
Output is correct |
49 |
Correct |
7 ms |
716 KB |
Output is correct |
50 |
Correct |
6 ms |
716 KB |
Output is correct |
51 |
Correct |
7 ms |
672 KB |
Output is correct |
52 |
Correct |
7 ms |
716 KB |
Output is correct |
53 |
Correct |
6 ms |
696 KB |
Output is correct |
54 |
Correct |
4 ms |
716 KB |
Output is correct |
55 |
Correct |
4 ms |
716 KB |
Output is correct |
56 |
Correct |
4 ms |
716 KB |
Output is correct |
57 |
Correct |
4 ms |
716 KB |
Output is correct |
58 |
Correct |
4 ms |
716 KB |
Output is correct |
59 |
Correct |
629 ms |
4400 KB |
Output is correct |
60 |
Correct |
611 ms |
4360 KB |
Output is correct |
61 |
Correct |
596 ms |
4252 KB |
Output is correct |
62 |
Correct |
645 ms |
4384 KB |
Output is correct |
63 |
Correct |
604 ms |
4436 KB |
Output is correct |
64 |
Correct |
833 ms |
4420 KB |
Output is correct |
65 |
Correct |
830 ms |
4420 KB |
Output is correct |
66 |
Correct |
830 ms |
4336 KB |
Output is correct |
67 |
Correct |
827 ms |
4340 KB |
Output is correct |
68 |
Correct |
844 ms |
4396 KB |
Output is correct |
69 |
Correct |
656 ms |
4292 KB |
Output is correct |
70 |
Correct |
675 ms |
4376 KB |
Output is correct |
71 |
Correct |
662 ms |
4308 KB |
Output is correct |
72 |
Correct |
666 ms |
4332 KB |
Output is correct |
73 |
Correct |
680 ms |
4352 KB |
Output is correct |
74 |
Correct |
127 ms |
2244 KB |
Output is correct |
75 |
Correct |
133 ms |
2372 KB |
Output is correct |
76 |
Correct |
132 ms |
2248 KB |
Output is correct |
77 |
Correct |
130 ms |
2360 KB |
Output is correct |
78 |
Correct |
127 ms |
2276 KB |
Output is correct |