| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1365932 | kmath628 | Exam (eJOI20_exam) | C++20 | 1096 ms | 23524 KiB |
#include <bits/stdc++.h>
using namespace std;
int a[100009],b[100009],dp[5009][5009];
int main(){
int n,i,j,l,r,d;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;i++) scanf("%d",&b[i]);
for(d=0;d<n;d++){
for(l=1;l<=n-d;l++){
r=l+d;
int opt=l;
for(i=l;i<=r;i++){
if(a[i]>a[opt]) opt=i;
}
int cnt=0;
for(i=opt;i>=l;i--){
if(a[opt]==b[i]) cnt++;
int cnt2=cnt;
for(j=opt;j<=r;j++){
if(j>opt && a[opt]==b[j]) cnt2++;
dp[l][r]=max(dp[l][r],dp[l][i-1]+dp[j+1][r]+cnt2);
}
}
}
}
printf("%d\n",dp[1][n]);
return 0;
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
