#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <functional>
#include <numeric>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
lint ipow(int x, int p){
lint ret = 1, piv = x;
while(p){
if(p & 1) ret *= piv;
piv *= piv;
ret %= mod;
piv %= mod;
p >>= 1;
}
return ret;
}
int n, s[505], e[505];
lint inv[1005], dp[505], sum[505], dp2[505][505];
vector<int> v;
int main(){
cin >> n;
for(int i=1; i<=n; i++){
cin >> s[i] >> e[i];
e[i]++;
v.push_back(s[i]);
v.push_back(e[i]);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for(int i=1; i<=1000; i++){
inv[i] = ipow(i, mod - 2);
}
dp[0] = 1;
for(int i=1; i<v.size(); i++){
int st = v[i-1], ed = v[i];
vector<int> cnd;
sum[0] = 1;
for(int j=1; j<=n; j++){
sum[j] = (sum[j-1] + dp[j]) % mod;
if(s[j] <= st && ed <= e[j]){
cnd.push_back(j);
}
}
for(int i=1; i<=cnd.size() && i <= ed - st; i++){
for(int j=i-1; j<cnd.size(); j++){
if(i == 1){
dp2[i][j] = sum[cnd[j] - 1] * (ed - st);
if(j) dp2[i][j] += dp2[i][j-1];
dp2[i][j] %= mod;
}
else{
dp2[i][j] = (dp2[i-1][j-1] * inv[i] % mod) * (ed - st + 1 - i) + dp2[i][j-1];
dp2[i][j] %= mod;
}
}
}
for(int i=1; i<=cnd.size() && i <= ed - st; i++){
for(int j=i-1; j<cnd.size(); j++){
int cnt = dp2[i][j] - (j ? dp2[i][j-1] : 0) + mod;
cnt %= mod;
dp[cnd[j]] += cnt;
dp[cnd[j]] %= mod;
}
}
}
int ret= 0;
for(int i=1; i<=n; i++){
ret += dp[i];
ret %= mod;
}
cout << ret;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i=1; i<v.size(); i++){
| ~^~~~~~~~~
boat.cpp:66:17: 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<=cnd.size() && i <= ed - st; i++){
| ~^~~~~~~~~~~~
boat.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j=i-1; j<cnd.size(); j++){
| ~^~~~~~~~~~~
boat.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i=1; i<=cnd.size() && i <= ed - st; i++){
| ~^~~~~~~~~~~~
boat.cpp:80:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int j=i-1; j<cnd.size(); j++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
488 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
488 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
488 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
488 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
9 ms |
592 KB |
Output is correct |
22 |
Correct |
10 ms |
592 KB |
Output is correct |
23 |
Correct |
10 ms |
592 KB |
Output is correct |
24 |
Correct |
9 ms |
580 KB |
Output is correct |
25 |
Correct |
10 ms |
592 KB |
Output is correct |
26 |
Correct |
10 ms |
584 KB |
Output is correct |
27 |
Correct |
11 ms |
580 KB |
Output is correct |
28 |
Correct |
10 ms |
504 KB |
Output is correct |
29 |
Correct |
10 ms |
592 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
440 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
3 ms |
464 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
4 ms |
668 KB |
Output is correct |
7 |
Correct |
4 ms |
848 KB |
Output is correct |
8 |
Correct |
4 ms |
848 KB |
Output is correct |
9 |
Correct |
4 ms |
832 KB |
Output is correct |
10 |
Correct |
4 ms |
848 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
3 ms |
592 KB |
Output is correct |
14 |
Correct |
3 ms |
592 KB |
Output is correct |
15 |
Correct |
3 ms |
664 KB |
Output is correct |
16 |
Correct |
2 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
488 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
488 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
9 ms |
592 KB |
Output is correct |
22 |
Correct |
10 ms |
592 KB |
Output is correct |
23 |
Correct |
10 ms |
592 KB |
Output is correct |
24 |
Correct |
9 ms |
580 KB |
Output is correct |
25 |
Correct |
10 ms |
592 KB |
Output is correct |
26 |
Correct |
10 ms |
584 KB |
Output is correct |
27 |
Correct |
11 ms |
580 KB |
Output is correct |
28 |
Correct |
10 ms |
504 KB |
Output is correct |
29 |
Correct |
10 ms |
592 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
440 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
3 ms |
464 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
592 KB |
Output is correct |
40 |
Correct |
2 ms |
444 KB |
Output is correct |
41 |
Correct |
2 ms |
592 KB |
Output is correct |
42 |
Correct |
2 ms |
592 KB |
Output is correct |
43 |
Correct |
3 ms |
592 KB |
Output is correct |
44 |
Correct |
4 ms |
668 KB |
Output is correct |
45 |
Correct |
4 ms |
848 KB |
Output is correct |
46 |
Correct |
4 ms |
848 KB |
Output is correct |
47 |
Correct |
4 ms |
832 KB |
Output is correct |
48 |
Correct |
4 ms |
848 KB |
Output is correct |
49 |
Correct |
2 ms |
592 KB |
Output is correct |
50 |
Correct |
2 ms |
592 KB |
Output is correct |
51 |
Correct |
3 ms |
592 KB |
Output is correct |
52 |
Correct |
3 ms |
592 KB |
Output is correct |
53 |
Correct |
3 ms |
664 KB |
Output is correct |
54 |
Correct |
2 ms |
592 KB |
Output is correct |
55 |
Correct |
2 ms |
592 KB |
Output is correct |
56 |
Correct |
2 ms |
592 KB |
Output is correct |
57 |
Correct |
2 ms |
592 KB |
Output is correct |
58 |
Correct |
2 ms |
592 KB |
Output is correct |
59 |
Correct |
137 ms |
1388 KB |
Output is correct |
60 |
Correct |
137 ms |
1384 KB |
Output is correct |
61 |
Correct |
124 ms |
1228 KB |
Output is correct |
62 |
Correct |
141 ms |
1352 KB |
Output is correct |
63 |
Correct |
127 ms |
1252 KB |
Output is correct |
64 |
Correct |
322 ms |
2380 KB |
Output is correct |
65 |
Correct |
318 ms |
2376 KB |
Output is correct |
66 |
Correct |
319 ms |
2324 KB |
Output is correct |
67 |
Correct |
334 ms |
2376 KB |
Output is correct |
68 |
Correct |
311 ms |
2376 KB |
Output is correct |
69 |
Correct |
116 ms |
1240 KB |
Output is correct |
70 |
Correct |
125 ms |
1624 KB |
Output is correct |
71 |
Correct |
116 ms |
1316 KB |
Output is correct |
72 |
Correct |
123 ms |
1272 KB |
Output is correct |
73 |
Correct |
123 ms |
1424 KB |
Output is correct |
74 |
Correct |
16 ms |
1360 KB |
Output is correct |
75 |
Correct |
15 ms |
1360 KB |
Output is correct |
76 |
Correct |
18 ms |
1428 KB |
Output is correct |
77 |
Correct |
17 ms |
1480 KB |
Output is correct |
78 |
Correct |
16 ms |
1536 KB |
Output is correct |