//srand(time(0)) - always changing
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
vector <int> a, b;
map <vector <int>, bool> was;
void rec(vector <int> a) {
if (was[a]) return;
else was[a] = 1;
for (int i = 0; i < n - 1; i++) {
int mn = a[i];
int mx = a[i];
for (int j = i + 1; j < n; j++) {
mn = min(mn, a[j]);
mx = max(mx, a[j]);
if (mn < mx) {
vector <int> act = a;
for (int k = i; k <= j; k++) {
act[k] = mx;
}
rec(act);
}
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) cnt++;
}
ans = max(ans, cnt);
}
void solve() {
bool sub1 = true;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a.push_back(x);
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
b.push_back(x);
if (i > 1) {
if (b[i - 1] != b[i - 2]) sub1 = false;
}
}
if (sub1) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) continue;
cnt++;
for (int j = i - 1; j >= 0; j--) {
if (a[j] >= a[i]) break;
a[j] = a[i];
cnt++;
// cout << j << ' ' << a[j] << ' ' << cnt << '\n';
}
int j = i + 1;
for (; j < n; j++) {
if (a[j] >= a[i]) break;
a[j] = a[i];
cnt++;
// cout << j << ' ' << a[j] << ' ' << cnt << '\n';
}
i = j + 1;
}
cout << cnt;
return;
}
rec(a);
cout << ans;
}
const bool Cases = 0;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TT = 1;
if (Cases) cin >> TT;
while (TT--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
124 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
460 ms |
8496 KB |
Output is correct |
2 |
Execution timed out |
1070 ms |
3544 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1079 ms |
295336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
124 ms |
2384 KB |
Output is correct |
7 |
Correct |
13 ms |
468 KB |
Output is correct |
8 |
Execution timed out |
1078 ms |
1964 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
124 ms |
2384 KB |
Output is correct |
7 |
Correct |
460 ms |
8496 KB |
Output is correct |
8 |
Execution timed out |
1070 ms |
3544 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |