이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long unsigned long ull;
typedef double long ld;
int n, a[100050], b[100050];
void solve2() {
for (int i = 1; i <= n; i++) {
if (a[i] == b[i]) {
for (int j = i + 1; j <= n; j++) {
if (a[j] >= a[i]) {
break;
}
a[j] = a[i];
}
for (int j = i - 1; j >= 1; j--) {
if (a[j] >= a[i]) {
break;
}
a[j] = a[i];
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += (a[i] == b[i] ? 1 : 0);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(!cin.tie(0));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
if (*max_element(b + 1, b + n + 1) == *min_element(b + 1, b + n + 1)) {
solve2();
return 0;
}
if (n <= 10) {
auto c = a;
int ans = 0;
function<void(int*)> Brut = [&](int* niz) {
int cnt = 0;
for (int i = 1; i <= n; i++) {
cnt += niz[i] == b[i];
}
ans = max(ans, cnt);
for (int i = 1; i <= n; i++) {
int mx = 0;
int novi[n + 1];
for (int j = 1; j <= n; j++) {
novi[j] = niz[j];
}
for (int j = i; j <= n; j++) {
mx = max(mx, niz[j]);
bool ok = false;
for (int l = i; l <= j; l++) {
if (niz[l] != mx) {
ok = true;
}
novi[l] = mx;
}
if (ok) {
Brut(novi);
}
}
}
};
Brut(c);
cout << ans << '\n';
}
}
| # | 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... |