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>
using namespace std;
typedef long long int lli;
typedef long double ld;
#define N lli(2e6)
#define MOD lli(1e9 + 7)
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define heps(v) v.begin(),v.end()
typedef vector<lli> vlli;
typedef pair<lli,lli> plli;
typedef pair<lli,plli> pplli;
typedef vector<plli> vplli;
typedef vector<pplli> vpplli;
typedef map<lli,lli> mlli;
lli t,n,m,k;
string str;
vlli a,b;
lli dp[N];
int main(){
fast_io
cin >>n;
for(lli i = 0;i<n;i++){
cin >> k;
a.push_back(k);
}
for(lli i = 0;i<n;i++){
cin >> k;
b.push_back(k);
}
lli enf = 0;
for(lli i = 0;i<n;i++){
lli sa = -1,so = -1;
lli sadeg = 0, sodeg = 0;
for(lli j = i;j<n;j++){
if(b[i] == b[j])
sadeg++;
if(b[i] == a[j]){
sa = j;
break;
}
if(a[j] >= b[i])
break;
}
for(lli j = i;j>=0;j--){
if(b[i] == b[j])
sodeg++;
if(b[i] == a[j]){
so = j;
break;
}
if(a[j] >= b[i])
break;
}
if(sa != -1){
lli enb = sadeg;
for(lli j = i-1;j>=0;j--){
enb = max(enb, sadeg + dp[j]);
if(b[j] == b[i])
sadeg++;
}
enb = max(enb,sadeg);
dp[sa] = max(dp[sa],enb);
enf = max(enf,dp[sa]);
}
if(so != -1){
lli enb = sodeg;
for(lli j = so-1;j>=0;j--){
enb = max(enb, sodeg + dp[j]);
if(b[j] == b[i])
sodeg++;
}
enb = max(enb,sodeg);
dp[i] = max(dp[i],enb);
enf = max(enf,dp[i]);
}
//cout << so << " " << sa << endl;
}
cout << enf << endl;
}
# | 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... |