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;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
if (count(b.begin(), b.end(), b[0]) == n) {
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] > b[0]) {
continue;
}
bool ok = false;
int j = i;
while (j < n && a[j] <= b[0]) {
ok |= a[j] == b[0];
j++;
}
if (ok) {
ans += j - i;
}
i = j - 1;
}
cout << ans << '\n';
return 0;
}
if (is_sorted(a.begin(), a.end())) {
vector<int> dp(n + 1);
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = i; j >= 0; j--) {
cnt += b[j] == a[i];
dp[i + 1] = max(dp[i + 1], dp[j] + cnt);
}
}
cout << dp[n] << '\n';
return 0;
}
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... |