#include <bits/stdc++.h>
using namespace std;
using i64=long long;
#define UNUSED -1
#define all(x) x.begin(),x.end()
#define pb push_back
const int mod=1e9+7,inf=1e9+1;
const i64 INF=1e18;
mt19937 rng(69);
int prod(int x,int y)
{
return (1LL*x*y)%mod;
}
int add(int x,int y)
{
assert(y>=0 && y<mod && x<mod);
return (x+y)%mod;
}
int pw2(int a,int p)
{
int rez=1;
while(p>0)
{
if(p&1)
{
rez=prod(rez,a);
}
p>>=1;
a=prod(a,a);
}
return rez;
}
const int N=500;
int dp[2*N+1][N+1],sum[2*N+1];
int fact[N+1],inv[N+1];
void pre_proc()
{
fact[0]=1,inv[0]=1;
for(int i=1;i<=N;i++)
{
fact[i]=prod(fact[i-1] , i);
inv[i]=pw2(fact[i] , mod-2);
}
}
int comb(int k,int n)
{
if(k>n)
{
return 0;
}
int rez=1;
for(int i=0;i<k;i++)
{
rez=prod(rez , n-i);
}
return prod(rez,inv[k]);
}
main()
{
pre_proc();
int n;
cin>>n;
//segmente de forma [x,y)
vector<pair<int,int>>a(n);
vector<int>poz(1,0);
poz.reserve(2*n+1);
for(auto &c:a)
{
cin>>c.first>>c.second;
c.second++;
poz.pb(c.first);
poz.pb(c.second);
}
sort(all(poz));
poz.erase(unique(all(poz)) , poz.end());
for(int i=0;i<poz.size()-1;i++)
{
sum[i]=1;
}
dp[0][1]=1;
vector<vector<int>>combb(poz.size()-1 , vector<int>(n+1));
for(int i=1;i<poz.size()-1;i++)
{
int aux=1;
for(int j=1;j<=n;j++)
{
aux=prod(aux , poz[i+1]-poz[i]-j+1);
combb[i][j]=prod(aux , inv[j]);
}
}
for(auto &c:a)
{
c.first=lower_bound(all(poz) , c.first)-poz.begin();
c.second=lower_bound(all(poz) , c.second)-poz.begin()-1;
for(int i=c.first;i<=c.second;i++)
{
for(int j=n;j>=2;j--)
{
dp[i][j]=add(dp[i][j] , dp[i][j-1]);
}
dp[i][1]=add(dp[i][1] , sum[i-1]);
}
for(int i=1;i<poz.size()-1;i++)
{
sum[i]=sum[i-1];
for(int j=1;j<=n;j++)
{
//if(c.first==2)cout<< prod(dp[i][j] , comb(j,poz[i+1]-poz[i]))<<' ';
sum[i]=add(sum[i] , prod(dp[i][j] , combb[i][j]));
}
//cout<<'\n';
//cout<<sum[i]<<' ';
}
//cout<<'\n';
}
cout<<sum[poz.size()-2]-1;
}
Compilation message
boat.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main()
| ^~~~
boat.cpp: In function 'int main()':
boat.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i=0;i<poz.size()-1;i++)
| ~^~~~~~~~~~~~~
boat.cpp:85:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=1;i<poz.size()-1;i++)
| ~^~~~~~~~~~~~~
boat.cpp:106:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i=1;i<poz.size()-1;i++)
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
929 ms |
4348 KB |
Output is correct |
2 |
Correct |
925 ms |
4176 KB |
Output is correct |
3 |
Correct |
919 ms |
4168 KB |
Output is correct |
4 |
Correct |
922 ms |
4384 KB |
Output is correct |
5 |
Correct |
926 ms |
4352 KB |
Output is correct |
6 |
Correct |
914 ms |
4316 KB |
Output is correct |
7 |
Correct |
920 ms |
4168 KB |
Output is correct |
8 |
Correct |
917 ms |
4168 KB |
Output is correct |
9 |
Correct |
907 ms |
4216 KB |
Output is correct |
10 |
Correct |
910 ms |
4292 KB |
Output is correct |
11 |
Correct |
911 ms |
4168 KB |
Output is correct |
12 |
Correct |
910 ms |
4296 KB |
Output is correct |
13 |
Correct |
912 ms |
4268 KB |
Output is correct |
14 |
Correct |
917 ms |
4168 KB |
Output is correct |
15 |
Correct |
924 ms |
4384 KB |
Output is correct |
16 |
Correct |
161 ms |
1096 KB |
Output is correct |
17 |
Correct |
175 ms |
1352 KB |
Output is correct |
18 |
Correct |
171 ms |
1104 KB |
Output is correct |
19 |
Correct |
174 ms |
1112 KB |
Output is correct |
20 |
Correct |
172 ms |
1096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
929 ms |
4348 KB |
Output is correct |
2 |
Correct |
925 ms |
4176 KB |
Output is correct |
3 |
Correct |
919 ms |
4168 KB |
Output is correct |
4 |
Correct |
922 ms |
4384 KB |
Output is correct |
5 |
Correct |
926 ms |
4352 KB |
Output is correct |
6 |
Correct |
914 ms |
4316 KB |
Output is correct |
7 |
Correct |
920 ms |
4168 KB |
Output is correct |
8 |
Correct |
917 ms |
4168 KB |
Output is correct |
9 |
Correct |
907 ms |
4216 KB |
Output is correct |
10 |
Correct |
910 ms |
4292 KB |
Output is correct |
11 |
Correct |
911 ms |
4168 KB |
Output is correct |
12 |
Correct |
910 ms |
4296 KB |
Output is correct |
13 |
Correct |
912 ms |
4268 KB |
Output is correct |
14 |
Correct |
917 ms |
4168 KB |
Output is correct |
15 |
Correct |
924 ms |
4384 KB |
Output is correct |
16 |
Correct |
161 ms |
1096 KB |
Output is correct |
17 |
Correct |
175 ms |
1352 KB |
Output is correct |
18 |
Correct |
171 ms |
1104 KB |
Output is correct |
19 |
Correct |
174 ms |
1112 KB |
Output is correct |
20 |
Correct |
172 ms |
1096 KB |
Output is correct |
21 |
Correct |
954 ms |
3920 KB |
Output is correct |
22 |
Correct |
952 ms |
4100 KB |
Output is correct |
23 |
Correct |
931 ms |
4004 KB |
Output is correct |
24 |
Correct |
927 ms |
4012 KB |
Output is correct |
25 |
Correct |
949 ms |
4024 KB |
Output is correct |
26 |
Correct |
966 ms |
3912 KB |
Output is correct |
27 |
Correct |
991 ms |
3916 KB |
Output is correct |
28 |
Correct |
978 ms |
3804 KB |
Output is correct |
29 |
Correct |
957 ms |
3852 KB |
Output is correct |
30 |
Correct |
918 ms |
4168 KB |
Output is correct |
31 |
Correct |
923 ms |
4224 KB |
Output is correct |
32 |
Correct |
916 ms |
4232 KB |
Output is correct |
33 |
Correct |
913 ms |
4320 KB |
Output is correct |
34 |
Correct |
910 ms |
4200 KB |
Output is correct |
35 |
Correct |
912 ms |
4148 KB |
Output is correct |
36 |
Correct |
917 ms |
4332 KB |
Output is correct |
37 |
Correct |
913 ms |
4168 KB |
Output is correct |
38 |
Correct |
918 ms |
4168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
848 KB |
Output is correct |
2 |
Correct |
9 ms |
928 KB |
Output is correct |
3 |
Correct |
10 ms |
848 KB |
Output is correct |
4 |
Correct |
10 ms |
928 KB |
Output is correct |
5 |
Correct |
10 ms |
848 KB |
Output is correct |
6 |
Correct |
10 ms |
908 KB |
Output is correct |
7 |
Correct |
10 ms |
912 KB |
Output is correct |
8 |
Correct |
11 ms |
848 KB |
Output is correct |
9 |
Correct |
10 ms |
848 KB |
Output is correct |
10 |
Correct |
10 ms |
1016 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
9 ms |
848 KB |
Output is correct |
13 |
Correct |
10 ms |
928 KB |
Output is correct |
14 |
Correct |
10 ms |
848 KB |
Output is correct |
15 |
Correct |
10 ms |
848 KB |
Output is correct |
16 |
Correct |
6 ms |
592 KB |
Output is correct |
17 |
Correct |
6 ms |
720 KB |
Output is correct |
18 |
Correct |
6 ms |
760 KB |
Output is correct |
19 |
Correct |
6 ms |
732 KB |
Output is correct |
20 |
Correct |
6 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
929 ms |
4348 KB |
Output is correct |
2 |
Correct |
925 ms |
4176 KB |
Output is correct |
3 |
Correct |
919 ms |
4168 KB |
Output is correct |
4 |
Correct |
922 ms |
4384 KB |
Output is correct |
5 |
Correct |
926 ms |
4352 KB |
Output is correct |
6 |
Correct |
914 ms |
4316 KB |
Output is correct |
7 |
Correct |
920 ms |
4168 KB |
Output is correct |
8 |
Correct |
917 ms |
4168 KB |
Output is correct |
9 |
Correct |
907 ms |
4216 KB |
Output is correct |
10 |
Correct |
910 ms |
4292 KB |
Output is correct |
11 |
Correct |
911 ms |
4168 KB |
Output is correct |
12 |
Correct |
910 ms |
4296 KB |
Output is correct |
13 |
Correct |
912 ms |
4268 KB |
Output is correct |
14 |
Correct |
917 ms |
4168 KB |
Output is correct |
15 |
Correct |
924 ms |
4384 KB |
Output is correct |
16 |
Correct |
161 ms |
1096 KB |
Output is correct |
17 |
Correct |
175 ms |
1352 KB |
Output is correct |
18 |
Correct |
171 ms |
1104 KB |
Output is correct |
19 |
Correct |
174 ms |
1112 KB |
Output is correct |
20 |
Correct |
172 ms |
1096 KB |
Output is correct |
21 |
Correct |
954 ms |
3920 KB |
Output is correct |
22 |
Correct |
952 ms |
4100 KB |
Output is correct |
23 |
Correct |
931 ms |
4004 KB |
Output is correct |
24 |
Correct |
927 ms |
4012 KB |
Output is correct |
25 |
Correct |
949 ms |
4024 KB |
Output is correct |
26 |
Correct |
966 ms |
3912 KB |
Output is correct |
27 |
Correct |
991 ms |
3916 KB |
Output is correct |
28 |
Correct |
978 ms |
3804 KB |
Output is correct |
29 |
Correct |
957 ms |
3852 KB |
Output is correct |
30 |
Correct |
918 ms |
4168 KB |
Output is correct |
31 |
Correct |
923 ms |
4224 KB |
Output is correct |
32 |
Correct |
916 ms |
4232 KB |
Output is correct |
33 |
Correct |
913 ms |
4320 KB |
Output is correct |
34 |
Correct |
910 ms |
4200 KB |
Output is correct |
35 |
Correct |
912 ms |
4148 KB |
Output is correct |
36 |
Correct |
917 ms |
4332 KB |
Output is correct |
37 |
Correct |
913 ms |
4168 KB |
Output is correct |
38 |
Correct |
918 ms |
4168 KB |
Output is correct |
39 |
Correct |
10 ms |
848 KB |
Output is correct |
40 |
Correct |
9 ms |
928 KB |
Output is correct |
41 |
Correct |
10 ms |
848 KB |
Output is correct |
42 |
Correct |
10 ms |
928 KB |
Output is correct |
43 |
Correct |
10 ms |
848 KB |
Output is correct |
44 |
Correct |
10 ms |
908 KB |
Output is correct |
45 |
Correct |
10 ms |
912 KB |
Output is correct |
46 |
Correct |
11 ms |
848 KB |
Output is correct |
47 |
Correct |
10 ms |
848 KB |
Output is correct |
48 |
Correct |
10 ms |
1016 KB |
Output is correct |
49 |
Correct |
10 ms |
848 KB |
Output is correct |
50 |
Correct |
9 ms |
848 KB |
Output is correct |
51 |
Correct |
10 ms |
928 KB |
Output is correct |
52 |
Correct |
10 ms |
848 KB |
Output is correct |
53 |
Correct |
10 ms |
848 KB |
Output is correct |
54 |
Correct |
6 ms |
592 KB |
Output is correct |
55 |
Correct |
6 ms |
720 KB |
Output is correct |
56 |
Correct |
6 ms |
760 KB |
Output is correct |
57 |
Correct |
6 ms |
732 KB |
Output is correct |
58 |
Correct |
6 ms |
592 KB |
Output is correct |
59 |
Correct |
1053 ms |
4580 KB |
Output is correct |
60 |
Correct |
1030 ms |
4168 KB |
Output is correct |
61 |
Correct |
1027 ms |
4176 KB |
Output is correct |
62 |
Correct |
1044 ms |
4404 KB |
Output is correct |
63 |
Correct |
1034 ms |
4176 KB |
Output is correct |
64 |
Correct |
1114 ms |
4368 KB |
Output is correct |
65 |
Correct |
1108 ms |
4224 KB |
Output is correct |
66 |
Correct |
1118 ms |
4168 KB |
Output is correct |
67 |
Correct |
1117 ms |
4336 KB |
Output is correct |
68 |
Correct |
1114 ms |
4360 KB |
Output is correct |
69 |
Correct |
1040 ms |
4176 KB |
Output is correct |
70 |
Correct |
1025 ms |
4420 KB |
Output is correct |
71 |
Correct |
1032 ms |
4400 KB |
Output is correct |
72 |
Correct |
1029 ms |
4396 KB |
Output is correct |
73 |
Correct |
1034 ms |
4388 KB |
Output is correct |
74 |
Correct |
196 ms |
1164 KB |
Output is correct |
75 |
Correct |
194 ms |
1104 KB |
Output is correct |
76 |
Correct |
197 ms |
1176 KB |
Output is correct |
77 |
Correct |
192 ms |
1172 KB |
Output is correct |
78 |
Correct |
192 ms |
1104 KB |
Output is correct |