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 <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
const int mxN = 2e6 + 1;
int a[mxN];
int b[mxN];
int dp[mxN];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >>n;
for(int i =0;i < n;i++){
cin >>a[i];
}
for(int i = 0;i < n;i++){
cin >>b[i];
}
for(int i = 0;i < n;i++){
if(i != 0)
dp[i] = dp[i - 1];
if(i == 0){
if(a[i] == b[i])
dp[i] = 1;
}
else if(a[i] <= b[i]){
for(int j = i;j >= 0;j--){
if(a[j] == b[i]){
dp[i] = max(dp[i - 1],dp[j] + 1);
}
if(a[j] > a[i])
break;
}
for(int j = i;j < n;j++){
if(a[j] == b[i]){
dp[i] = max(dp[i],dp[i - 1] + 1);
}
if(a[j] > a[i])
break;
}
}
}
cout <<dp[n - 1];
}
// nice
# | 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... |