이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: milos
* created: 16.04.2021 02:05:22
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
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];
}
bool same = true;
for (int i = 0; i < n; i++) {
if (b[i] != b[0]) {
same = false;
}
}
if (same) {
vector<int> pos;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) {
pos.push_back(i);
}
}
for (int i : pos) {
for (int j = i + 1; j < n; j++) {
if (a[j] >= b[j]) {
break;
}
a[j] = a[i];
}
for (int j = i - 1; j >= 0; j--) {
if (a[j] >= b[j]) {
break;
}
a[j] = a[i];
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) {
cnt++;
}
}
cout << cnt << '\n';
return 0;
}
vector<int> dp(n);
for (int i = 0; i < n; i++) {
if (i > 0) {
dp[i] = dp[i - 1];
}
int add = 0;
for (int j = i - 1; j >= 0; j--) {
if (a[j] > a[i]) {
dp[i] = max(dp[i], dp[j] + add);
break;
}
int fk = 0;
if (j > 0) fk = dp[j - 1];
if (a[i] == b[j]) {
add++;
}
dp[i] = max(dp[i], fk + add);
}
int mx = a[i];
map<int, int> cnt;
cnt[b[i]] += 1;
for (int j = i - 1; j >= 0; j--) {
mx = max(mx, a[j]);
if (mx == a[j]) {
dp[i] = max(dp[i], dp[j] + cnt[a[j]]);
} else {
break;
}
cnt[b[j]] += 1;
}
if (a[i] == b[i]) {
dp[i]++;
}
}
cout << dp[n - 1] << '\n';
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... |