이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<int> a(n), b(n);
for (int &x : a) {
cin >> x;
}
for (int &x : b) {
cin >> x;
}
if (n > 5000) {
int res = 0;
for (int i = 0; i < n; ++i) {
if (a[i] > b[0]) {
continue;
}
int j = i - 1;
bool flg = 0;
while (j + 1 < n && a[j + 1] <= b[0]) {
flg |= a[++j] == b[0];
}
res += flg * (j - i + 1);
i = j;
}
cout << res;
exit(0);
}
vector<int> comp;
for (int i = 0; i < n; ++i) {
comp.push_back(a[i]);
comp.push_back(b[i]);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin();
b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin();
}
int m = comp.size();
vector<int> dp(n + 1), cnt(m);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
dp[i] = dp[i - 1];
int ma = 0;
for (int j = i - 1; j >= 0; --j) {
ma = max(ma, a[j]);
++cnt[b[j]];
dp[i] = max(dp[i], dp[j] + cnt[ma]);
}
for (int j = 0; j < i; ++j) {
cnt[b[j]] = 0;
}
}
cout << dp.back();
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... |