#include <stdio.h>
#include <vector>
#include <algorithm>
#define ll long long
#define MOD 1'000'000'007
using namespace std;
int A[521], B[521];
vector<int> X;
ll inv[521];
ll dp1[521], dp2[521][521], sum[521];
ll get_inv(ll x, ll y = MOD-2){
ll z = y & 1 ? x : 1;
while(y >>= 1){
x = x*x%MOD;
if(y & 1) z = z*x%MOD;
}
return z;
}
int main(){
int n; scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d %d", &A[i], &B[i]);
for(int i = 1; i <= n; i++){
X.push_back(A[i]);
X.push_back(B[i]+1);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
for(int i = 1; i <= n; i++){
A[i] = lower_bound(X.begin(), X.end(), A[i])-X.begin()+1;
B[i] = lower_bound(X.begin(), X.end(), B[i]+1)-X.begin();
}
for(int i = 1; i <= n; i++) inv[i] = get_inv(i);
dp1[0] = 1;
for(int i = 1; i < X.size(); i++){
for(int j = 0; j <= n; j++) dp2[j][0] = dp1[j];
fill(dp1, dp1+n+1, 0);
fill(sum, sum+n+1, 0);
int cnt = 0;
dp1[0] = sum[0] = dp2[0][0];
for(int j = 1; j <= n; j++){
if(A[j] <= i && B[j] >= i){
int l = X[i]-X[i-1]; cnt++;
for(int k = min(cnt, l); k >= 1; k--){
dp2[j][k] = sum[k-1]*(l-k+1)%MOD*inv[k]%MOD;
dp1[j] = (dp1[j]+dp2[j][k])%MOD;
sum[k] = (sum[k]+dp2[j][k])%MOD;
}
}
dp1[j] = (dp1[j]+dp2[j][0])%MOD;
sum[0] = (sum[0]+dp2[j][0])%MOD;
}
}
ll ans = 0;
for(int i = 1; i <= n; i++) ans = (ans+dp1[i])%MOD;
printf("%lld", ans);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 1; i < X.size(); i++){
| ~~^~~~~~~~~~
boat.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:26:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | for(int i = 1; i <= n; i++) scanf("%d %d", &A[i], &B[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2260 KB |
Output is correct |
2 |
Correct |
5 ms |
2228 KB |
Output is correct |
3 |
Correct |
5 ms |
2332 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
5 ms |
2260 KB |
Output is correct |
6 |
Correct |
5 ms |
2328 KB |
Output is correct |
7 |
Correct |
5 ms |
2260 KB |
Output is correct |
8 |
Correct |
5 ms |
2224 KB |
Output is correct |
9 |
Correct |
5 ms |
2260 KB |
Output is correct |
10 |
Correct |
6 ms |
2260 KB |
Output is correct |
11 |
Correct |
5 ms |
2224 KB |
Output is correct |
12 |
Correct |
5 ms |
2260 KB |
Output is correct |
13 |
Correct |
5 ms |
2336 KB |
Output is correct |
14 |
Correct |
5 ms |
2224 KB |
Output is correct |
15 |
Correct |
5 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2228 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2260 KB |
Output is correct |
2 |
Correct |
5 ms |
2228 KB |
Output is correct |
3 |
Correct |
5 ms |
2332 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
5 ms |
2260 KB |
Output is correct |
6 |
Correct |
5 ms |
2328 KB |
Output is correct |
7 |
Correct |
5 ms |
2260 KB |
Output is correct |
8 |
Correct |
5 ms |
2224 KB |
Output is correct |
9 |
Correct |
5 ms |
2260 KB |
Output is correct |
10 |
Correct |
6 ms |
2260 KB |
Output is correct |
11 |
Correct |
5 ms |
2224 KB |
Output is correct |
12 |
Correct |
5 ms |
2260 KB |
Output is correct |
13 |
Correct |
5 ms |
2336 KB |
Output is correct |
14 |
Correct |
5 ms |
2224 KB |
Output is correct |
15 |
Correct |
5 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2228 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
21 |
Correct |
12 ms |
2260 KB |
Output is correct |
22 |
Correct |
12 ms |
2260 KB |
Output is correct |
23 |
Correct |
11 ms |
2260 KB |
Output is correct |
24 |
Correct |
12 ms |
2260 KB |
Output is correct |
25 |
Correct |
12 ms |
2260 KB |
Output is correct |
26 |
Correct |
13 ms |
2356 KB |
Output is correct |
27 |
Correct |
12 ms |
2352 KB |
Output is correct |
28 |
Correct |
11 ms |
2260 KB |
Output is correct |
29 |
Correct |
12 ms |
2364 KB |
Output is correct |
30 |
Correct |
5 ms |
2260 KB |
Output is correct |
31 |
Correct |
5 ms |
2340 KB |
Output is correct |
32 |
Correct |
5 ms |
2260 KB |
Output is correct |
33 |
Correct |
6 ms |
2328 KB |
Output is correct |
34 |
Correct |
5 ms |
2260 KB |
Output is correct |
35 |
Correct |
5 ms |
2260 KB |
Output is correct |
36 |
Correct |
5 ms |
2260 KB |
Output is correct |
37 |
Correct |
5 ms |
2332 KB |
Output is correct |
38 |
Correct |
5 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
680 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
684 KB |
Output is correct |
7 |
Correct |
4 ms |
680 KB |
Output is correct |
8 |
Correct |
3 ms |
680 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
680 KB |
Output is correct |
14 |
Correct |
2 ms |
688 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
684 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2260 KB |
Output is correct |
2 |
Correct |
5 ms |
2228 KB |
Output is correct |
3 |
Correct |
5 ms |
2332 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
5 ms |
2260 KB |
Output is correct |
6 |
Correct |
5 ms |
2328 KB |
Output is correct |
7 |
Correct |
5 ms |
2260 KB |
Output is correct |
8 |
Correct |
5 ms |
2224 KB |
Output is correct |
9 |
Correct |
5 ms |
2260 KB |
Output is correct |
10 |
Correct |
6 ms |
2260 KB |
Output is correct |
11 |
Correct |
5 ms |
2224 KB |
Output is correct |
12 |
Correct |
5 ms |
2260 KB |
Output is correct |
13 |
Correct |
5 ms |
2336 KB |
Output is correct |
14 |
Correct |
5 ms |
2224 KB |
Output is correct |
15 |
Correct |
5 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2228 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
21 |
Correct |
12 ms |
2260 KB |
Output is correct |
22 |
Correct |
12 ms |
2260 KB |
Output is correct |
23 |
Correct |
11 ms |
2260 KB |
Output is correct |
24 |
Correct |
12 ms |
2260 KB |
Output is correct |
25 |
Correct |
12 ms |
2260 KB |
Output is correct |
26 |
Correct |
13 ms |
2356 KB |
Output is correct |
27 |
Correct |
12 ms |
2352 KB |
Output is correct |
28 |
Correct |
11 ms |
2260 KB |
Output is correct |
29 |
Correct |
12 ms |
2364 KB |
Output is correct |
30 |
Correct |
5 ms |
2260 KB |
Output is correct |
31 |
Correct |
5 ms |
2340 KB |
Output is correct |
32 |
Correct |
5 ms |
2260 KB |
Output is correct |
33 |
Correct |
6 ms |
2328 KB |
Output is correct |
34 |
Correct |
5 ms |
2260 KB |
Output is correct |
35 |
Correct |
5 ms |
2260 KB |
Output is correct |
36 |
Correct |
5 ms |
2260 KB |
Output is correct |
37 |
Correct |
5 ms |
2332 KB |
Output is correct |
38 |
Correct |
5 ms |
2260 KB |
Output is correct |
39 |
Correct |
2 ms |
724 KB |
Output is correct |
40 |
Correct |
1 ms |
724 KB |
Output is correct |
41 |
Correct |
2 ms |
680 KB |
Output is correct |
42 |
Correct |
2 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
724 KB |
Output is correct |
44 |
Correct |
4 ms |
684 KB |
Output is correct |
45 |
Correct |
4 ms |
680 KB |
Output is correct |
46 |
Correct |
3 ms |
680 KB |
Output is correct |
47 |
Correct |
4 ms |
724 KB |
Output is correct |
48 |
Correct |
3 ms |
684 KB |
Output is correct |
49 |
Correct |
2 ms |
724 KB |
Output is correct |
50 |
Correct |
2 ms |
596 KB |
Output is correct |
51 |
Correct |
2 ms |
680 KB |
Output is correct |
52 |
Correct |
2 ms |
688 KB |
Output is correct |
53 |
Correct |
2 ms |
724 KB |
Output is correct |
54 |
Correct |
1 ms |
724 KB |
Output is correct |
55 |
Correct |
1 ms |
724 KB |
Output is correct |
56 |
Correct |
1 ms |
684 KB |
Output is correct |
57 |
Correct |
1 ms |
724 KB |
Output is correct |
58 |
Correct |
1 ms |
724 KB |
Output is correct |
59 |
Correct |
140 ms |
2348 KB |
Output is correct |
60 |
Correct |
121 ms |
2336 KB |
Output is correct |
61 |
Correct |
116 ms |
2352 KB |
Output is correct |
62 |
Correct |
137 ms |
2348 KB |
Output is correct |
63 |
Correct |
132 ms |
2320 KB |
Output is correct |
64 |
Correct |
310 ms |
2340 KB |
Output is correct |
65 |
Correct |
314 ms |
2344 KB |
Output is correct |
66 |
Correct |
303 ms |
2336 KB |
Output is correct |
67 |
Correct |
314 ms |
2508 KB |
Output is correct |
68 |
Correct |
313 ms |
2340 KB |
Output is correct |
69 |
Correct |
114 ms |
2336 KB |
Output is correct |
70 |
Correct |
116 ms |
2340 KB |
Output is correct |
71 |
Correct |
116 ms |
2332 KB |
Output is correct |
72 |
Correct |
128 ms |
2464 KB |
Output is correct |
73 |
Correct |
124 ms |
2340 KB |
Output is correct |
74 |
Correct |
15 ms |
2364 KB |
Output is correct |
75 |
Correct |
15 ms |
2260 KB |
Output is correct |
76 |
Correct |
15 ms |
2260 KB |
Output is correct |
77 |
Correct |
15 ms |
2356 KB |
Output is correct |
78 |
Correct |
19 ms |
2360 KB |
Output is correct |