# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
76782 |
2018-09-17T19:14:28 Z |
vex |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
5180 KB |
#include <bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
#define maxn 505
#define mod (long long)(1e9 + 7)
using namespace std;
long long ste(long long x,long long y)
{
if(y==0)return 1LL;
if(y%2==1)return (x*ste(x,y-1))%mod;
long long ss=ste(x,y/2);
return (ss*ss)%mod;
}
long long fact[2*maxn];
long long invf[2*maxn];
void precalc()
{
fact[0]=1;
for(int i=1;i<=1000;i++)
{
fact[i]=fact[i-1]*i;
fact[i]%=mod;
}
for(int i=0;i<=1000;i++)
invf[i]=ste(fact[i],mod-2);
}
long long bc(int x,int y)
{
if(x<y)return 0;
if(x<=1000)return (((fact[x]*invf[y])%mod) * invf[x-y] )%mod;
long long res=1;
for(int i=0;i<y;i++)
{
res*=(x-i);
res%=mod;
}
return (res*invf[y])%mod;
}
int n;
int d[2*maxn];
pii t[maxn];
long long dp[2*maxn][maxn];
vector<int>tre;
long long pre[maxn];
long long f[2*maxn],gf[2*maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
precalc();
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t[i].f>>t[i].s;
d[2*i-1]=t[i].f;
d[2*i]=t[i].s;
}
sort(d+1,d+1+2*n);
for(int i=1;i<=n;i++)dp[0][i]=0LL;
for(int i=1;i<=n;i++)if(t[i].f==d[1])dp[0][i]=1LL;
dp[0][0]=1LL;
//for(int i=1;i<=n;i++)cout<<dp[0][i]<<" "<<t[i].f<<" "<<d[0]<<endl;
for(int i=1;i<=2*n-1;i++)
{
for(int j=0;j<=n;j++)dp[i][j]=dp[i-1][j];
if(d[i]==d[i+1])continue;
tre.clear();
for(int j=0;j<=n;j++)
{
f[j]=0;
pre[j]=0;
gf[j]=0;
}
for(int j=1;j<=n;j++)
{
if(t[j].f==d[i+1]);
else if(t[j].f<=d[i] && d[i+1]<=t[j].s);
else continue;
for(int k=0;k<j;k++)
{
pre[j]+=dp[i-1][k];
pre[j]%=mod;
}
if(t[j].f==d[i+1])
{
int sz=tre.size();
int dd=min(d[i+1]-d[i]-1,sz);
for(int k=1;k<=dd;k++)
{
long long sss=0;
for(int kk=sz-k;kk>=0;kk--)
{
sss+=pre[tre[kk]]*bc(sz-kk-1,k-1);
sss%=mod;
}
dp[i][j]+=sss*bc(d[i+1]-d[i]-1,k);
dp[i][j]%=mod;
}
dp[i][j]+=pre[j];
dp[i][j]%=mod;
}
else if(t[j].f<=d[i] && d[i+1]<=t[j].s)
{
int sz=tre.size();
int dd=min(d[i+1]-d[i],sz+1);
for(int k=2;k<=dd;k++)
{
long long sss=0;
for(int kk=sz+1-k;kk>=0;kk--)
{
sss+=pre[tre[kk]]*bc(sz-1-kk,k-2);
sss%=mod;
}
dp[i][j]+=sss*bc(d[i+1]-d[i],k);
dp[i][j]%=mod;
}
dp[i][j]+=pre[j]*(d[i+1]-d[i]);
dp[i][j]%=mod;
tre.push_back(j);
}
/*if(t[j].f==d[i+1])
{
int sz=tre.size();
int dd=min(d[i+1]-d[i]-1,sz);
for(int k=1;k<=dd;k++)
{
dp[i][j]+=bc(d[i+1]-d[i]-1,k)*f[k];
dp[i][j]%=mod;
}
dp[i][j]+=pre[j];
}
else if(t[j].f<=d[i] && d[i+1]<=t[j].s)
{
int sz=tre.size();
int dd=min(d[i+1]-d[i],sz+1);
dp[i][j]+=(d[i+1]-d[i])*pre[j];
dp[i][j]%=mod;
for(int k=2;k<=dd;k++)
{
dp[i][j]+=bc(d[i+1]-d[i],k)*gf[k];
dp[i][j]%=mod;
}
for(int k=dd;k>2;k--)
{
gf[k]+=gf[k-1];
gf[k]%=mod;
}
gf[2]+=pre[j];
gf[2]%=mod;
///!!!!!
///BAGA OVDE
tre.push_back(j);
sz++;
if(sz+1<=d[i+1]-d[i])
{
gf[sz+2]=pre[tre[0]];
}
for(int k=dd;k>1;k--)
{
f[k]+=f[k-1];
f[k]%=mod;
}
f[1]+=pre[j];
f[1]%=mod;
if(sz<=d[i+1]-d[i])
{
f[sz]=pre[tre[0]];
}
}*/
}
//for(int j=1;j<=n;j++)cout<<pre[j]<<" ";cout<<endl;
}
//for(int i=1;i<=n;i++)cout<<i<<" "<<t[i].f<<" "<<t[i].s<<endl;
//for(int i=1;i<=2*n;i++)cout<<d[i]<<" ";cout<<endl;
/*for(int i=0;i<=2*n-1;i++)
{
cout<<i<<" ";
for(int j=1;j<=n;j++)cout<<dp[i][j]<<" ";
cout<<endl;
}*/
long long sol=0;
for(int i=1;i<=n;i++)
{
sol+=dp[2*n-1][i];
sol%=mod;
}
cout<<sol<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4444 KB |
Output is correct |
2 |
Correct |
9 ms |
4540 KB |
Output is correct |
3 |
Correct |
8 ms |
4540 KB |
Output is correct |
4 |
Correct |
8 ms |
4540 KB |
Output is correct |
5 |
Correct |
9 ms |
4552 KB |
Output is correct |
6 |
Correct |
8 ms |
4652 KB |
Output is correct |
7 |
Correct |
8 ms |
4652 KB |
Output is correct |
8 |
Correct |
8 ms |
4756 KB |
Output is correct |
9 |
Correct |
8 ms |
4756 KB |
Output is correct |
10 |
Correct |
8 ms |
4756 KB |
Output is correct |
11 |
Correct |
8 ms |
4756 KB |
Output is correct |
12 |
Correct |
9 ms |
4756 KB |
Output is correct |
13 |
Correct |
8 ms |
4756 KB |
Output is correct |
14 |
Correct |
8 ms |
4756 KB |
Output is correct |
15 |
Correct |
8 ms |
4756 KB |
Output is correct |
16 |
Correct |
7 ms |
4756 KB |
Output is correct |
17 |
Correct |
7 ms |
4764 KB |
Output is correct |
18 |
Correct |
7 ms |
4844 KB |
Output is correct |
19 |
Correct |
7 ms |
4844 KB |
Output is correct |
20 |
Correct |
7 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4444 KB |
Output is correct |
2 |
Correct |
9 ms |
4540 KB |
Output is correct |
3 |
Correct |
8 ms |
4540 KB |
Output is correct |
4 |
Correct |
8 ms |
4540 KB |
Output is correct |
5 |
Correct |
9 ms |
4552 KB |
Output is correct |
6 |
Correct |
8 ms |
4652 KB |
Output is correct |
7 |
Correct |
8 ms |
4652 KB |
Output is correct |
8 |
Correct |
8 ms |
4756 KB |
Output is correct |
9 |
Correct |
8 ms |
4756 KB |
Output is correct |
10 |
Correct |
8 ms |
4756 KB |
Output is correct |
11 |
Correct |
8 ms |
4756 KB |
Output is correct |
12 |
Correct |
9 ms |
4756 KB |
Output is correct |
13 |
Correct |
8 ms |
4756 KB |
Output is correct |
14 |
Correct |
8 ms |
4756 KB |
Output is correct |
15 |
Correct |
8 ms |
4756 KB |
Output is correct |
16 |
Correct |
7 ms |
4756 KB |
Output is correct |
17 |
Correct |
7 ms |
4764 KB |
Output is correct |
18 |
Correct |
7 ms |
4844 KB |
Output is correct |
19 |
Correct |
7 ms |
4844 KB |
Output is correct |
20 |
Correct |
7 ms |
4844 KB |
Output is correct |
21 |
Correct |
868 ms |
4952 KB |
Output is correct |
22 |
Correct |
859 ms |
4952 KB |
Output is correct |
23 |
Correct |
748 ms |
5060 KB |
Output is correct |
24 |
Correct |
872 ms |
5060 KB |
Output is correct |
25 |
Correct |
887 ms |
5060 KB |
Output is correct |
26 |
Correct |
1378 ms |
5060 KB |
Output is correct |
27 |
Correct |
1464 ms |
5060 KB |
Output is correct |
28 |
Correct |
1451 ms |
5084 KB |
Output is correct |
29 |
Correct |
1445 ms |
5084 KB |
Output is correct |
30 |
Correct |
11 ms |
5084 KB |
Output is correct |
31 |
Correct |
18 ms |
5084 KB |
Output is correct |
32 |
Correct |
11 ms |
5128 KB |
Output is correct |
33 |
Correct |
11 ms |
5128 KB |
Output is correct |
34 |
Correct |
10 ms |
5128 KB |
Output is correct |
35 |
Correct |
9 ms |
5128 KB |
Output is correct |
36 |
Correct |
9 ms |
5180 KB |
Output is correct |
37 |
Correct |
9 ms |
5180 KB |
Output is correct |
38 |
Correct |
9 ms |
5180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
5180 KB |
Output is correct |
2 |
Correct |
21 ms |
5180 KB |
Output is correct |
3 |
Correct |
31 ms |
5180 KB |
Output is correct |
4 |
Correct |
34 ms |
5180 KB |
Output is correct |
5 |
Correct |
43 ms |
5180 KB |
Output is correct |
6 |
Correct |
132 ms |
5180 KB |
Output is correct |
7 |
Correct |
136 ms |
5180 KB |
Output is correct |
8 |
Correct |
132 ms |
5180 KB |
Output is correct |
9 |
Correct |
136 ms |
5180 KB |
Output is correct |
10 |
Correct |
131 ms |
5180 KB |
Output is correct |
11 |
Correct |
41 ms |
5180 KB |
Output is correct |
12 |
Correct |
24 ms |
5180 KB |
Output is correct |
13 |
Correct |
33 ms |
5180 KB |
Output is correct |
14 |
Correct |
32 ms |
5180 KB |
Output is correct |
15 |
Correct |
43 ms |
5180 KB |
Output is correct |
16 |
Correct |
18 ms |
5180 KB |
Output is correct |
17 |
Correct |
15 ms |
5180 KB |
Output is correct |
18 |
Correct |
16 ms |
5180 KB |
Output is correct |
19 |
Correct |
14 ms |
5180 KB |
Output is correct |
20 |
Correct |
22 ms |
5180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4444 KB |
Output is correct |
2 |
Correct |
9 ms |
4540 KB |
Output is correct |
3 |
Correct |
8 ms |
4540 KB |
Output is correct |
4 |
Correct |
8 ms |
4540 KB |
Output is correct |
5 |
Correct |
9 ms |
4552 KB |
Output is correct |
6 |
Correct |
8 ms |
4652 KB |
Output is correct |
7 |
Correct |
8 ms |
4652 KB |
Output is correct |
8 |
Correct |
8 ms |
4756 KB |
Output is correct |
9 |
Correct |
8 ms |
4756 KB |
Output is correct |
10 |
Correct |
8 ms |
4756 KB |
Output is correct |
11 |
Correct |
8 ms |
4756 KB |
Output is correct |
12 |
Correct |
9 ms |
4756 KB |
Output is correct |
13 |
Correct |
8 ms |
4756 KB |
Output is correct |
14 |
Correct |
8 ms |
4756 KB |
Output is correct |
15 |
Correct |
8 ms |
4756 KB |
Output is correct |
16 |
Correct |
7 ms |
4756 KB |
Output is correct |
17 |
Correct |
7 ms |
4764 KB |
Output is correct |
18 |
Correct |
7 ms |
4844 KB |
Output is correct |
19 |
Correct |
7 ms |
4844 KB |
Output is correct |
20 |
Correct |
7 ms |
4844 KB |
Output is correct |
21 |
Correct |
868 ms |
4952 KB |
Output is correct |
22 |
Correct |
859 ms |
4952 KB |
Output is correct |
23 |
Correct |
748 ms |
5060 KB |
Output is correct |
24 |
Correct |
872 ms |
5060 KB |
Output is correct |
25 |
Correct |
887 ms |
5060 KB |
Output is correct |
26 |
Correct |
1378 ms |
5060 KB |
Output is correct |
27 |
Correct |
1464 ms |
5060 KB |
Output is correct |
28 |
Correct |
1451 ms |
5084 KB |
Output is correct |
29 |
Correct |
1445 ms |
5084 KB |
Output is correct |
30 |
Correct |
11 ms |
5084 KB |
Output is correct |
31 |
Correct |
18 ms |
5084 KB |
Output is correct |
32 |
Correct |
11 ms |
5128 KB |
Output is correct |
33 |
Correct |
11 ms |
5128 KB |
Output is correct |
34 |
Correct |
10 ms |
5128 KB |
Output is correct |
35 |
Correct |
9 ms |
5128 KB |
Output is correct |
36 |
Correct |
9 ms |
5180 KB |
Output is correct |
37 |
Correct |
9 ms |
5180 KB |
Output is correct |
38 |
Correct |
9 ms |
5180 KB |
Output is correct |
39 |
Correct |
35 ms |
5180 KB |
Output is correct |
40 |
Correct |
21 ms |
5180 KB |
Output is correct |
41 |
Correct |
31 ms |
5180 KB |
Output is correct |
42 |
Correct |
34 ms |
5180 KB |
Output is correct |
43 |
Correct |
43 ms |
5180 KB |
Output is correct |
44 |
Correct |
132 ms |
5180 KB |
Output is correct |
45 |
Correct |
136 ms |
5180 KB |
Output is correct |
46 |
Correct |
132 ms |
5180 KB |
Output is correct |
47 |
Correct |
136 ms |
5180 KB |
Output is correct |
48 |
Correct |
131 ms |
5180 KB |
Output is correct |
49 |
Correct |
41 ms |
5180 KB |
Output is correct |
50 |
Correct |
24 ms |
5180 KB |
Output is correct |
51 |
Correct |
33 ms |
5180 KB |
Output is correct |
52 |
Correct |
32 ms |
5180 KB |
Output is correct |
53 |
Correct |
43 ms |
5180 KB |
Output is correct |
54 |
Correct |
18 ms |
5180 KB |
Output is correct |
55 |
Correct |
15 ms |
5180 KB |
Output is correct |
56 |
Correct |
16 ms |
5180 KB |
Output is correct |
57 |
Correct |
14 ms |
5180 KB |
Output is correct |
58 |
Correct |
22 ms |
5180 KB |
Output is correct |
59 |
Execution timed out |
2055 ms |
5180 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |