#include <iostream>
#include<map>
#include<cstdio>
#include<set>
using namespace std;
#define MN 1000000007
#define mult(a, b) a*1LL*b%MN
#define x first
#define ll long long
#define ub upper_bound
#define y second
short l2, l3,n, p, c;
bool k[505][1005];
int a[505], b[505], rev[1005], ncr2[1005][505];
ll ans, dp[1005][1005], t[1005][1005],
ncr[1005][505], ncrt[505][505], cnt[1005];
map<int, short> m;
//set<int> s;
int main() {
cin >> n;
for (short l=1; l<=n; ++l){
scanf("%i%i", &a[l], &b[l]); b[l]++;
if (m.count(a[l])==0) m[a[l]]=0;
if (m.count(b[l])==0) m[b[l]]=0;
m[a[l]]++; m[b[l]]--; //s.insert(a[l]); s.insert(b[l]);
}
for (auto i:m){
c+=i.y;
rev[m[i.x]=++p]=i.x;
cnt[p]=c;
}
c=0;
for (short l=1; l<m.size(); ++l){
ncr[l][0]=1;
for (l2=1; l2<=cnt[l]; ++l2){
if (l2>rev[l+1]-rev[l]+1) break;
ncr[l][l2]=(ncr[l][l2-1]*(rev[l+1]-rev[l]+1-l2))%MN;
while(ncr[l][l2]%l2) ncr[l][l2]+=MN;
ncr[l][l2]=(ncr[l][l2]/l2)%MN;
}
}
for (short l=0; l<=500; ++l){
ncrt[l][0]=1;
for (l2=1; l2<=l; ++l2){
ncrt[l][l2]=(ncrt[l][l2-1]*(l+1-l2))%MN;
while(ncrt[l][l2]%l2) ncrt[l][l2]+=MN;
ncrt[l][l2]=(ncrt[l][l2]/l2)%MN;
}
}
for (short l=1; l<m.size(); ++l){
for (l2=2; l2<=cnt[l]; ++l2){
for (l3=2; l3<=l2; ++l3){
ncr2[l][l2]=(ncr2[l][l2]+ncr[l][l3]*ncrt[l2-2][l3-2])%MN;
}
}
}
for (short l=1; l<=n; ++l){
a[l]=m[a[l]]; b[l]=m[b[l]];
for (l2=1; l2<a[l]; ++l2){
t[l][l2]=(t[l-1][l2]+t[l][l2-1]-t[l-1][l2-1])%MN;
if (t[l][l2]<0) t[l][l2]+=MN;
}
for (l2=a[l]; l2<b[l]; ++l2){
c=k[l][l2]=1;
dp[l][l2]=(dp[l][l2]+(t[l-1][l2-1]+1)*ncr[l2][1])%MN;
//cout << dp[l][l2] << ' ' ;
for (l3=l-1; l3>0; --l3){
if (k[l3][l2])
dp[l][l2]=(dp[l][l2]+(t[l3-1][l2-1]+1)*ncr2[l2][++c])%MN;
}
t[l][l2]=(t[l-1][l2]+t[l][l2-1]-t[l-1][l2-1]+dp[l][l2])%MN;
ans=(ans+dp[l][l2])%MN;
}
for (l2=b[l]; l2<m.size(); ++l2){
t[l][l2]=(t[l-1][l2]+t[l][l2-1]-t[l-1][l2-1])%MN;
if (t[l][l2]<0) t[l][l2]+=MN;
//cout << t[l][l2] << ' ';
}
//cout << endl;
}
cout << ans;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (short l=1; l<m.size(); ++l){
^
boat.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (short l=1; l<m.size(); ++l){
^
boat.cpp:75:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (l2=b[l]; l2<m.size(); ++l2){
^
boat.cpp:23:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &a[l], &b[l]); b[l]++;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
26252 KB |
Output is correct |
2 |
Correct |
136 ms |
26252 KB |
Output is correct |
3 |
Correct |
149 ms |
26252 KB |
Output is correct |
4 |
Correct |
146 ms |
26252 KB |
Output is correct |
5 |
Correct |
146 ms |
26252 KB |
Output is correct |
6 |
Correct |
153 ms |
26252 KB |
Output is correct |
7 |
Correct |
146 ms |
26252 KB |
Output is correct |
8 |
Correct |
143 ms |
26252 KB |
Output is correct |
9 |
Correct |
139 ms |
26252 KB |
Output is correct |
10 |
Correct |
143 ms |
26252 KB |
Output is correct |
11 |
Correct |
143 ms |
26252 KB |
Output is correct |
12 |
Correct |
136 ms |
26252 KB |
Output is correct |
13 |
Correct |
139 ms |
26252 KB |
Output is correct |
14 |
Correct |
139 ms |
26252 KB |
Output is correct |
15 |
Correct |
136 ms |
26252 KB |
Output is correct |
16 |
Correct |
129 ms |
26252 KB |
Output is correct |
17 |
Correct |
146 ms |
26252 KB |
Output is correct |
18 |
Correct |
136 ms |
26252 KB |
Output is correct |
19 |
Correct |
146 ms |
26252 KB |
Output is correct |
20 |
Correct |
153 ms |
26252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
26252 KB |
Output is correct |
2 |
Correct |
136 ms |
26252 KB |
Output is correct |
3 |
Correct |
149 ms |
26252 KB |
Output is correct |
4 |
Correct |
146 ms |
26252 KB |
Output is correct |
5 |
Correct |
146 ms |
26252 KB |
Output is correct |
6 |
Correct |
153 ms |
26252 KB |
Output is correct |
7 |
Correct |
146 ms |
26252 KB |
Output is correct |
8 |
Correct |
143 ms |
26252 KB |
Output is correct |
9 |
Correct |
139 ms |
26252 KB |
Output is correct |
10 |
Correct |
143 ms |
26252 KB |
Output is correct |
11 |
Correct |
143 ms |
26252 KB |
Output is correct |
12 |
Correct |
136 ms |
26252 KB |
Output is correct |
13 |
Correct |
139 ms |
26252 KB |
Output is correct |
14 |
Correct |
139 ms |
26252 KB |
Output is correct |
15 |
Correct |
136 ms |
26252 KB |
Output is correct |
16 |
Correct |
129 ms |
26252 KB |
Output is correct |
17 |
Correct |
146 ms |
26252 KB |
Output is correct |
18 |
Correct |
136 ms |
26252 KB |
Output is correct |
19 |
Correct |
146 ms |
26252 KB |
Output is correct |
20 |
Correct |
153 ms |
26252 KB |
Output is correct |
21 |
Correct |
429 ms |
26252 KB |
Output is correct |
22 |
Correct |
473 ms |
26252 KB |
Output is correct |
23 |
Correct |
399 ms |
26252 KB |
Output is correct |
24 |
Correct |
426 ms |
26252 KB |
Output is correct |
25 |
Correct |
453 ms |
26252 KB |
Output is correct |
26 |
Correct |
723 ms |
26252 KB |
Output is correct |
27 |
Correct |
756 ms |
26252 KB |
Output is correct |
28 |
Correct |
726 ms |
26252 KB |
Output is correct |
29 |
Correct |
746 ms |
26252 KB |
Output is correct |
30 |
Correct |
143 ms |
26252 KB |
Output is correct |
31 |
Correct |
139 ms |
26252 KB |
Output is correct |
32 |
Correct |
146 ms |
26252 KB |
Output is correct |
33 |
Correct |
133 ms |
26252 KB |
Output is correct |
34 |
Correct |
143 ms |
26252 KB |
Output is correct |
35 |
Correct |
149 ms |
26252 KB |
Output is correct |
36 |
Correct |
149 ms |
26252 KB |
Output is correct |
37 |
Correct |
143 ms |
26252 KB |
Output is correct |
38 |
Correct |
149 ms |
26252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
26252 KB |
Output is correct |
2 |
Correct |
146 ms |
26252 KB |
Output is correct |
3 |
Correct |
139 ms |
26252 KB |
Output is correct |
4 |
Correct |
149 ms |
26252 KB |
Output is correct |
5 |
Correct |
153 ms |
26252 KB |
Output is correct |
6 |
Correct |
139 ms |
26252 KB |
Output is correct |
7 |
Correct |
146 ms |
26252 KB |
Output is correct |
8 |
Correct |
149 ms |
26252 KB |
Output is correct |
9 |
Correct |
146 ms |
26252 KB |
Output is correct |
10 |
Correct |
146 ms |
26252 KB |
Output is correct |
11 |
Correct |
143 ms |
26252 KB |
Output is correct |
12 |
Correct |
139 ms |
26252 KB |
Output is correct |
13 |
Correct |
169 ms |
26252 KB |
Output is correct |
14 |
Correct |
136 ms |
26252 KB |
Output is correct |
15 |
Correct |
146 ms |
26252 KB |
Output is correct |
16 |
Correct |
143 ms |
26252 KB |
Output is correct |
17 |
Correct |
143 ms |
26252 KB |
Output is correct |
18 |
Correct |
139 ms |
26252 KB |
Output is correct |
19 |
Correct |
139 ms |
26252 KB |
Output is correct |
20 |
Correct |
143 ms |
26252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
26252 KB |
Output is correct |
2 |
Correct |
136 ms |
26252 KB |
Output is correct |
3 |
Correct |
149 ms |
26252 KB |
Output is correct |
4 |
Correct |
146 ms |
26252 KB |
Output is correct |
5 |
Correct |
146 ms |
26252 KB |
Output is correct |
6 |
Correct |
153 ms |
26252 KB |
Output is correct |
7 |
Correct |
146 ms |
26252 KB |
Output is correct |
8 |
Correct |
143 ms |
26252 KB |
Output is correct |
9 |
Correct |
139 ms |
26252 KB |
Output is correct |
10 |
Correct |
143 ms |
26252 KB |
Output is correct |
11 |
Correct |
143 ms |
26252 KB |
Output is correct |
12 |
Correct |
136 ms |
26252 KB |
Output is correct |
13 |
Correct |
139 ms |
26252 KB |
Output is correct |
14 |
Correct |
139 ms |
26252 KB |
Output is correct |
15 |
Correct |
136 ms |
26252 KB |
Output is correct |
16 |
Correct |
129 ms |
26252 KB |
Output is correct |
17 |
Correct |
146 ms |
26252 KB |
Output is correct |
18 |
Correct |
136 ms |
26252 KB |
Output is correct |
19 |
Correct |
146 ms |
26252 KB |
Output is correct |
20 |
Correct |
153 ms |
26252 KB |
Output is correct |
21 |
Correct |
429 ms |
26252 KB |
Output is correct |
22 |
Correct |
473 ms |
26252 KB |
Output is correct |
23 |
Correct |
399 ms |
26252 KB |
Output is correct |
24 |
Correct |
426 ms |
26252 KB |
Output is correct |
25 |
Correct |
453 ms |
26252 KB |
Output is correct |
26 |
Correct |
723 ms |
26252 KB |
Output is correct |
27 |
Correct |
756 ms |
26252 KB |
Output is correct |
28 |
Correct |
726 ms |
26252 KB |
Output is correct |
29 |
Correct |
746 ms |
26252 KB |
Output is correct |
30 |
Correct |
143 ms |
26252 KB |
Output is correct |
31 |
Correct |
139 ms |
26252 KB |
Output is correct |
32 |
Correct |
146 ms |
26252 KB |
Output is correct |
33 |
Correct |
133 ms |
26252 KB |
Output is correct |
34 |
Correct |
143 ms |
26252 KB |
Output is correct |
35 |
Correct |
149 ms |
26252 KB |
Output is correct |
36 |
Correct |
149 ms |
26252 KB |
Output is correct |
37 |
Correct |
143 ms |
26252 KB |
Output is correct |
38 |
Correct |
149 ms |
26252 KB |
Output is correct |
39 |
Correct |
156 ms |
26252 KB |
Output is correct |
40 |
Correct |
146 ms |
26252 KB |
Output is correct |
41 |
Correct |
139 ms |
26252 KB |
Output is correct |
42 |
Correct |
149 ms |
26252 KB |
Output is correct |
43 |
Correct |
153 ms |
26252 KB |
Output is correct |
44 |
Correct |
139 ms |
26252 KB |
Output is correct |
45 |
Correct |
146 ms |
26252 KB |
Output is correct |
46 |
Correct |
149 ms |
26252 KB |
Output is correct |
47 |
Correct |
146 ms |
26252 KB |
Output is correct |
48 |
Correct |
146 ms |
26252 KB |
Output is correct |
49 |
Correct |
143 ms |
26252 KB |
Output is correct |
50 |
Correct |
139 ms |
26252 KB |
Output is correct |
51 |
Correct |
169 ms |
26252 KB |
Output is correct |
52 |
Correct |
136 ms |
26252 KB |
Output is correct |
53 |
Correct |
146 ms |
26252 KB |
Output is correct |
54 |
Correct |
143 ms |
26252 KB |
Output is correct |
55 |
Correct |
143 ms |
26252 KB |
Output is correct |
56 |
Correct |
139 ms |
26252 KB |
Output is correct |
57 |
Correct |
139 ms |
26252 KB |
Output is correct |
58 |
Correct |
143 ms |
26252 KB |
Output is correct |
59 |
Correct |
596 ms |
26252 KB |
Output is correct |
60 |
Correct |
573 ms |
26252 KB |
Output is correct |
61 |
Correct |
519 ms |
26252 KB |
Output is correct |
62 |
Correct |
643 ms |
26252 KB |
Output is correct |
63 |
Correct |
593 ms |
26252 KB |
Output is correct |
64 |
Correct |
1093 ms |
26252 KB |
Output is correct |
65 |
Correct |
1086 ms |
26252 KB |
Output is correct |
66 |
Correct |
1109 ms |
26252 KB |
Output is correct |
67 |
Correct |
1109 ms |
26252 KB |
Output is correct |
68 |
Correct |
1036 ms |
26252 KB |
Output is correct |
69 |
Correct |
486 ms |
26252 KB |
Output is correct |
70 |
Correct |
503 ms |
26252 KB |
Output is correct |
71 |
Correct |
509 ms |
26252 KB |
Output is correct |
72 |
Correct |
593 ms |
26252 KB |
Output is correct |
73 |
Correct |
589 ms |
26252 KB |
Output is correct |
74 |
Correct |
239 ms |
26252 KB |
Output is correct |
75 |
Correct |
249 ms |
26252 KB |
Output is correct |
76 |
Correct |
256 ms |
26252 KB |
Output is correct |
77 |
Correct |
266 ms |
26252 KB |
Output is correct |
78 |
Correct |
226 ms |
26252 KB |
Output is correct |