Submission #928565

#TimeUsernameProblemLanguageResultExecution timeMemory
928565activedeltorreExam (eJOI20_exam)C++14
65 / 100
152 ms98536 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...