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;
#define int long long
const int N = 2e5 + 1;
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n , oK = 1;cin >> n;
vector<int> a(n + 1) , b(n + 1);
for(int i = 1;i <= n;i ++){
cin >> a[i];
}
for(int i = 1;i <= n;i ++){
cin >> b[i];
if(i != 1) oK &= (b[i] == b[i - 1]);
}
if(oK){
int c = 0;
for(int i = 1;i <= n;i ++){
int cc = 0 , k = 0;
while(a[i] <= b[i] && i <= n){
if(a[i] == b[i]) k = 1;
++ cc , ++ i;
}
if(k) c += cc;
}
cout << c << endl;
}else{
oK = 1;
for(int i = 2;i <= n;i ++){
oK &= (a[i] > a[i - 1]);
}
if(oK){
vector<int> dp(n + 1);
dp[1] = (a[1] == b[1]);
for(int i = 2;i <= n;i ++){
int q = 0;
for(int j = i;j >= 1;j --){
q += (a[i] == b[j]);
dp[i] = max(dp[i] , q + dp[j - 1]);
dp[j] = max(dp[j] , dp[j - 1] + (a[i] == b[j]));
}
}
cout << *max_element(dp.begin() , dp.end()) << endl;
}
}
}
Compilation message (stderr)
exam.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~
# | 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... |