This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
int a[5005];
int b[5005];
int st[5005];
int dr[5005];
int dp[5005][5005];
int main()
{
int n,i,j;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
for(i=1;i<=n;i++)
{
cin>>b[i];
}
for(i=1;i<=n;i++)
{
st[i]=i;
while(a[i]>=a[st[i]] && st[i]>=1)
{
st[i]--;
}
st[i]++;
dr[i]=i;
while(a[i]>=a[dr[i]] && dr[i]<=n)
{
dr[i]++;
}
dr[i]--;
}
int sol=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[i]==b[j] && st[i]<=j && j<=dr[i])
{
dp[i][j]=max(dp[i][j],dp[i][j-1]+1);
}
else
{
dp[i][j]=max(dp[i][j],dp[i][j-1]);
dp[i][j]=max(dp[i][j],dp[i-1][j]);
}
sol=max(sol,dp[i][j]);
}
}
cout<<sol;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |