이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 5005;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n), b(n), c;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
c.push_back(a[i]);
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
c.push_back(b[i]);
}
std::sort(c.begin(), c.end());
c.erase(std::unique(c.begin(), c.end()), c.end());
for (int i = 0; i < n; i++) {
a[i] = std::lower_bound(c.begin(), c.end(), a[i]) - c.begin();
b[i] = std::lower_bound(c.begin(), c.end(), b[i]) - c.begin();
}
if (n <= 5000) {
std::vector<int> dp(n + 1);
for (int i = 1; i <= n; i++) {
std::vector<int> cnt(c.size());
for (int j = i, mx = 0; j >= 1; j--) {
mx = std::max(mx, a[j - 1]);
cnt[b[j - 1]]++;
dp[i] = std::max(dp[i], dp[j - 1] + cnt[mx]);
}
for (int j = i, mx = 0; j >= 1; j--) {
mx = std::max(mx, a[j - 1]);
if (mx == b[j - 1]) {
dp[j] = std::max(dp[j], dp[j - 1] + 1);
}
}
}
std::cout << dp[n] << "\n";
} else {
if (std::count(b.begin(), b.end(), b[0]) == n) {
std::vector<int> t(n, 0);
for (int i = 0; i < n; i++) {
if (a[i] == b[0]) {
int j = i;
while (j >= 0 && a[j] <= b[0] && !t[j]) {
t[j--] = 1;
}
j = i + 1;
while (j < n && a[j] <= b[0] && !t[j]) {
t[j++] = 1;
}
}
}
std::cout << std::accumulate(t.begin(), t.end(), 0) << "\n";
} else {
}
}
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... |