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 ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1), r(n + 1);
map<int, int> pos;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pos[a[i]] = i;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
}
for (int i = n; i >= 1; --i) {
r[i] = pos[b[i]];
}
vector<int> dp(n + 1, 0);
for (int i = n; i >= 1; --i) {
if (r[i] == 0) {
dp[i] = dp[i + 1];
continue;
}
int ans = 0;
for (int j = i; j <= r[i]; ++j) ans += b[j] == b[i];
dp[i] = max(dp[i + 1], dp[r[i] + 1] + ans);
}
cout << dp[1] << endl;
return 0;
}
# | 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... |