#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)
#define PB push_back
const int MAXN=510, MOD=1000000007;
int n, le[MAXN], ri[MAXN], arr[2*MAXN][MAXN], inv[MAXN];
bool adj[2*MAXN][MAXN];
vector<int> pt;
ll ex(ll b, int e){
ll ret=1;
while(e>0){
if(e&1) ret=(ret*b)%MOD;
b = (b*b)%MOD;
e>>=1;
}
return ret;
}
int main(){
scanf("%d", &n);
forn(i, n+2) inv[i]=ex(i, MOD-2);
forn(i, n) scanf("%d %d", le+i, ri+i), pt.PB(le[i]), pt.PB(ri[i]+1);
sort(pt.begin(), pt.end());
pt.erase(unique(pt.begin(), pt.end()), pt.end());
forn(i, n){
auto itr = lower_bound(pt.begin(), pt.end(), le[i]);
for(; itr!=pt.end() && (*itr)<=ri[i]; ++itr) adj[itr-pt.begin()][i]=true;
}
forn(i, pt.size()-1){
forn(j, n){
arr[i+1][j]=(arr[i][j]-(j==0? 0 : arr[i][j-1]) + MOD)%MOD;
if(adj[i][j]){
int cnt=0, m=pt[i+1]-pt[i];
ll comb=m;
dforn(k, j){
int dif = (arr[i][k] - (k==0? 0 : arr[i][k-1]) + MOD)%MOD;
arr[i+1][j]=(arr[i+1][j] + comb*dif)%MOD;
if(adj[i][k]){
++cnt;
comb=(((comb*(m+cnt))%MOD)*((ll)inv[cnt+1]))%MOD;
}
}
arr[i+1][j]=(arr[i+1][j]+comb)%MOD;
}
}
forn(j, n-1) arr[i+1][j+1]=(arr[i+1][j+1]+arr[i+1][j])%MOD;
}
printf("%d\n", arr[pt.size()-1][n-1]);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:28:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | forn(i, n) scanf("%d %d", le+i, ri+i), pt.PB(le[i]), pt.PB(ri[i]+1);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2772 KB |
Output is correct |
2 |
Correct |
6 ms |
2772 KB |
Output is correct |
3 |
Correct |
5 ms |
2772 KB |
Output is correct |
4 |
Correct |
5 ms |
2772 KB |
Output is correct |
5 |
Correct |
4 ms |
2768 KB |
Output is correct |
6 |
Correct |
5 ms |
2772 KB |
Output is correct |
7 |
Correct |
5 ms |
2772 KB |
Output is correct |
8 |
Correct |
5 ms |
2772 KB |
Output is correct |
9 |
Correct |
4 ms |
2772 KB |
Output is correct |
10 |
Correct |
4 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
2772 KB |
Output is correct |
13 |
Correct |
4 ms |
2772 KB |
Output is correct |
14 |
Correct |
4 ms |
2772 KB |
Output is correct |
15 |
Correct |
4 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2772 KB |
Output is correct |
2 |
Correct |
6 ms |
2772 KB |
Output is correct |
3 |
Correct |
5 ms |
2772 KB |
Output is correct |
4 |
Correct |
5 ms |
2772 KB |
Output is correct |
5 |
Correct |
4 ms |
2768 KB |
Output is correct |
6 |
Correct |
5 ms |
2772 KB |
Output is correct |
7 |
Correct |
5 ms |
2772 KB |
Output is correct |
8 |
Correct |
5 ms |
2772 KB |
Output is correct |
9 |
Correct |
4 ms |
2772 KB |
Output is correct |
10 |
Correct |
4 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
2772 KB |
Output is correct |
13 |
Correct |
4 ms |
2772 KB |
Output is correct |
14 |
Correct |
4 ms |
2772 KB |
Output is correct |
15 |
Correct |
4 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
212 ms |
2568 KB |
Output is correct |
22 |
Correct |
205 ms |
2552 KB |
Output is correct |
23 |
Correct |
199 ms |
2560 KB |
Output is correct |
24 |
Correct |
216 ms |
2508 KB |
Output is correct |
25 |
Correct |
203 ms |
2468 KB |
Output is correct |
26 |
Correct |
416 ms |
2508 KB |
Output is correct |
27 |
Correct |
444 ms |
2440 KB |
Output is correct |
28 |
Correct |
417 ms |
2424 KB |
Output is correct |
29 |
Correct |
414 ms |
2400 KB |
Output is correct |
30 |
Correct |
6 ms |
2772 KB |
Output is correct |
31 |
Correct |
5 ms |
2756 KB |
Output is correct |
32 |
Correct |
6 ms |
2772 KB |
Output is correct |
33 |
Correct |
6 ms |
2772 KB |
Output is correct |
34 |
Correct |
6 ms |
2772 KB |
Output is correct |
35 |
Correct |
6 ms |
2772 KB |
Output is correct |
36 |
Correct |
6 ms |
2712 KB |
Output is correct |
37 |
Correct |
6 ms |
2772 KB |
Output is correct |
38 |
Correct |
5 ms |
2756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2772 KB |
Output is correct |
2 |
Correct |
6 ms |
2772 KB |
Output is correct |
3 |
Correct |
5 ms |
2772 KB |
Output is correct |
4 |
Correct |
5 ms |
2772 KB |
Output is correct |
5 |
Correct |
4 ms |
2768 KB |
Output is correct |
6 |
Correct |
5 ms |
2772 KB |
Output is correct |
7 |
Correct |
5 ms |
2772 KB |
Output is correct |
8 |
Correct |
5 ms |
2772 KB |
Output is correct |
9 |
Correct |
4 ms |
2772 KB |
Output is correct |
10 |
Correct |
4 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
2772 KB |
Output is correct |
13 |
Correct |
4 ms |
2772 KB |
Output is correct |
14 |
Correct |
4 ms |
2772 KB |
Output is correct |
15 |
Correct |
4 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
212 ms |
2568 KB |
Output is correct |
22 |
Correct |
205 ms |
2552 KB |
Output is correct |
23 |
Correct |
199 ms |
2560 KB |
Output is correct |
24 |
Correct |
216 ms |
2508 KB |
Output is correct |
25 |
Correct |
203 ms |
2468 KB |
Output is correct |
26 |
Correct |
416 ms |
2508 KB |
Output is correct |
27 |
Correct |
444 ms |
2440 KB |
Output is correct |
28 |
Correct |
417 ms |
2424 KB |
Output is correct |
29 |
Correct |
414 ms |
2400 KB |
Output is correct |
30 |
Correct |
6 ms |
2772 KB |
Output is correct |
31 |
Correct |
5 ms |
2756 KB |
Output is correct |
32 |
Correct |
6 ms |
2772 KB |
Output is correct |
33 |
Correct |
6 ms |
2772 KB |
Output is correct |
34 |
Correct |
6 ms |
2772 KB |
Output is correct |
35 |
Correct |
6 ms |
2772 KB |
Output is correct |
36 |
Correct |
6 ms |
2712 KB |
Output is correct |
37 |
Correct |
6 ms |
2772 KB |
Output is correct |
38 |
Correct |
5 ms |
2756 KB |
Output is correct |
39 |
Correct |
2 ms |
724 KB |
Output is correct |
40 |
Correct |
2 ms |
724 KB |
Output is correct |
41 |
Correct |
2 ms |
724 KB |
Output is correct |
42 |
Correct |
3 ms |
724 KB |
Output is correct |
43 |
Correct |
3 ms |
724 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
4 ms |
724 KB |
Output is correct |
46 |
Correct |
4 ms |
724 KB |
Output is correct |
47 |
Correct |
4 ms |
724 KB |
Output is correct |
48 |
Correct |
5 ms |
724 KB |
Output is correct |
49 |
Correct |
3 ms |
724 KB |
Output is correct |
50 |
Correct |
2 ms |
724 KB |
Output is correct |
51 |
Correct |
2 ms |
724 KB |
Output is correct |
52 |
Correct |
2 ms |
724 KB |
Output is correct |
53 |
Correct |
2 ms |
724 KB |
Output is correct |
54 |
Correct |
2 ms |
596 KB |
Output is correct |
55 |
Correct |
1 ms |
596 KB |
Output is correct |
56 |
Correct |
2 ms |
596 KB |
Output is correct |
57 |
Correct |
2 ms |
592 KB |
Output is correct |
58 |
Correct |
2 ms |
596 KB |
Output is correct |
59 |
Correct |
240 ms |
2708 KB |
Output is correct |
60 |
Correct |
218 ms |
2728 KB |
Output is correct |
61 |
Correct |
203 ms |
2796 KB |
Output is correct |
62 |
Correct |
235 ms |
2860 KB |
Output is correct |
63 |
Correct |
221 ms |
2792 KB |
Output is correct |
64 |
Correct |
479 ms |
2856 KB |
Output is correct |
65 |
Correct |
477 ms |
2720 KB |
Output is correct |
66 |
Correct |
479 ms |
2812 KB |
Output is correct |
67 |
Correct |
480 ms |
2756 KB |
Output is correct |
68 |
Correct |
476 ms |
2892 KB |
Output is correct |
69 |
Correct |
188 ms |
2724 KB |
Output is correct |
70 |
Correct |
201 ms |
2920 KB |
Output is correct |
71 |
Correct |
186 ms |
2808 KB |
Output is correct |
72 |
Correct |
200 ms |
2800 KB |
Output is correct |
73 |
Correct |
217 ms |
2740 KB |
Output is correct |
74 |
Correct |
45 ms |
728 KB |
Output is correct |
75 |
Correct |
43 ms |
712 KB |
Output is correct |
76 |
Correct |
45 ms |
700 KB |
Output is correct |
77 |
Correct |
45 ms |
712 KB |
Output is correct |
78 |
Correct |
56 ms |
756 KB |
Output is correct |