#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;
}
bool sub3 = true;
for (int i = 2; i <= n; i++) {
if (a[i] <= a[i - 1]) {
sub3 = false;
}
}
if (sub3) {
map<int, int> mp;
for (int i = 1; i <= n; i++) {
mp[a[i]] = 1;
}
vector<int> c;
for (int i = 1; i <= n; i++) {
if (mp[b[i]]) {
c.push_back(b[i]);
}
}
n = (int) c.size();
vector<int> dp(n);
for (int i = 0; i < n; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (c[i] >= c[j]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
cout << *max_element(dp.begin(), dp.end()) << '\n';
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 |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
33 ms |
300 KB |
Output is correct |
4 |
Correct |
53 ms |
304 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
204 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
460 KB |
Output is correct |
3 |
Correct |
19 ms |
1012 KB |
Output is correct |
4 |
Correct |
16 ms |
1100 KB |
Output is correct |
5 |
Correct |
28 ms |
1004 KB |
Output is correct |
6 |
Correct |
19 ms |
1084 KB |
Output is correct |
7 |
Correct |
17 ms |
1096 KB |
Output is correct |
8 |
Correct |
26 ms |
964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
33 ms |
300 KB |
Output is correct |
4 |
Correct |
53 ms |
304 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
204 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
33 ms |
300 KB |
Output is correct |
4 |
Correct |
53 ms |
304 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
204 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |