# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
76735 |
2018-09-16T23:20:13 Z |
vex |
Boat (APIO16_boat) |
C++14 |
|
311 ms |
4740 KB |
#include <bits/stdc++.h>
#define maxn 505
#define f first
#define s second
#define pii pair<int,int>
#define mod (long long)(1e9 + 7)
using namespace std;
int n;
int a[maxn][2];
pii d[2*maxn];
int pl[maxn];
int pr[maxn];
long long dp[2*maxn][maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i][0]>>a[i][1];
d[2*i-1]={a[i][0],0};
d[2*i]={a[i][1],1};
pl[i]=a[i][0];
pr[i]=a[i][1];
}
sort(d+1,d+2*n+1);
for(int i=1;i<=n;i++)dp[0][i]=0;
dp[0][0]=1;
for(int j=1;j<=n;j++)if(pl[j]==d[1].f)dp[0][j]=1;
for(int i=1;i<=2*n-1;i++)
{
dp[i][0]=1;
for(int j=1;j<=n;j++)
{
dp[i][j]=dp[i-1][j];
int dod=0;
if(d[i].f==d[i+1].f)continue;
if(pl[j]==d[i+1].f)dod=1;
else if(pl[j]<=d[i].f && d[i+1].f<=pr[j])dod=d[i+1].f-d[i].f;
else continue;
//cout<<i<<" "<<j<<" "<<dod<<endl;
for(int k=0;k<j;k++)
{
dp[i][j]+=dp[i-1][k]*dod;
dp[i][j]%=mod;
if(pl[j]==d[i+1].f && pl[k]<=d[i].f && d[i+1].f<=pr[k])
{
dp[i][j]+=(dp[i][k]-dp[i-1][k])*(d[i+1].f-d[i].f-1)/(d[i+1].f-d[i].f);
dp[i][j]%=mod;
}
}
}
}
long long sol=0;
for(int i=1;i<=n;i++)
{
sol+=dp[2*n-1][i];
sol%=mod;
}
//for(int i=1;i<=2*n;i++)cout<<d[i].f<<" "<<d[i].s<<endl;cout<<endl;
/*for(int i=1;i<=n;i++)cout<<i<<" "<<pl[i]<<" "<<pr[i]<<endl;cout<<endl;
for(int i=0;i<=2*n-1;i++)
{
cout<<i<<" ";
for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
cout<<endl;
}*/
cout<<sol<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4316 KB |
Output is correct |
2 |
Correct |
8 ms |
4604 KB |
Output is correct |
3 |
Correct |
8 ms |
4604 KB |
Output is correct |
4 |
Correct |
7 ms |
4604 KB |
Output is correct |
5 |
Correct |
7 ms |
4604 KB |
Output is correct |
6 |
Correct |
6 ms |
4604 KB |
Output is correct |
7 |
Correct |
6 ms |
4604 KB |
Output is correct |
8 |
Correct |
6 ms |
4604 KB |
Output is correct |
9 |
Correct |
6 ms |
4604 KB |
Output is correct |
10 |
Correct |
7 ms |
4604 KB |
Output is correct |
11 |
Correct |
7 ms |
4604 KB |
Output is correct |
12 |
Correct |
6 ms |
4604 KB |
Output is correct |
13 |
Correct |
7 ms |
4604 KB |
Output is correct |
14 |
Correct |
6 ms |
4604 KB |
Output is correct |
15 |
Correct |
6 ms |
4604 KB |
Output is correct |
16 |
Correct |
7 ms |
4604 KB |
Output is correct |
17 |
Correct |
6 ms |
4604 KB |
Output is correct |
18 |
Correct |
6 ms |
4604 KB |
Output is correct |
19 |
Correct |
6 ms |
4612 KB |
Output is correct |
20 |
Correct |
8 ms |
4624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4316 KB |
Output is correct |
2 |
Correct |
8 ms |
4604 KB |
Output is correct |
3 |
Correct |
8 ms |
4604 KB |
Output is correct |
4 |
Correct |
7 ms |
4604 KB |
Output is correct |
5 |
Correct |
7 ms |
4604 KB |
Output is correct |
6 |
Correct |
6 ms |
4604 KB |
Output is correct |
7 |
Correct |
6 ms |
4604 KB |
Output is correct |
8 |
Correct |
6 ms |
4604 KB |
Output is correct |
9 |
Correct |
6 ms |
4604 KB |
Output is correct |
10 |
Correct |
7 ms |
4604 KB |
Output is correct |
11 |
Correct |
7 ms |
4604 KB |
Output is correct |
12 |
Correct |
6 ms |
4604 KB |
Output is correct |
13 |
Correct |
7 ms |
4604 KB |
Output is correct |
14 |
Correct |
6 ms |
4604 KB |
Output is correct |
15 |
Correct |
6 ms |
4604 KB |
Output is correct |
16 |
Correct |
7 ms |
4604 KB |
Output is correct |
17 |
Correct |
6 ms |
4604 KB |
Output is correct |
18 |
Correct |
6 ms |
4604 KB |
Output is correct |
19 |
Correct |
6 ms |
4612 KB |
Output is correct |
20 |
Correct |
8 ms |
4624 KB |
Output is correct |
21 |
Incorrect |
311 ms |
4740 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4316 KB |
Output is correct |
2 |
Correct |
8 ms |
4604 KB |
Output is correct |
3 |
Correct |
8 ms |
4604 KB |
Output is correct |
4 |
Correct |
7 ms |
4604 KB |
Output is correct |
5 |
Correct |
7 ms |
4604 KB |
Output is correct |
6 |
Correct |
6 ms |
4604 KB |
Output is correct |
7 |
Correct |
6 ms |
4604 KB |
Output is correct |
8 |
Correct |
6 ms |
4604 KB |
Output is correct |
9 |
Correct |
6 ms |
4604 KB |
Output is correct |
10 |
Correct |
7 ms |
4604 KB |
Output is correct |
11 |
Correct |
7 ms |
4604 KB |
Output is correct |
12 |
Correct |
6 ms |
4604 KB |
Output is correct |
13 |
Correct |
7 ms |
4604 KB |
Output is correct |
14 |
Correct |
6 ms |
4604 KB |
Output is correct |
15 |
Correct |
6 ms |
4604 KB |
Output is correct |
16 |
Correct |
7 ms |
4604 KB |
Output is correct |
17 |
Correct |
6 ms |
4604 KB |
Output is correct |
18 |
Correct |
6 ms |
4604 KB |
Output is correct |
19 |
Correct |
6 ms |
4612 KB |
Output is correct |
20 |
Correct |
8 ms |
4624 KB |
Output is correct |
21 |
Incorrect |
311 ms |
4740 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |