#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#define x first
#define y second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 10;
int b[MAX_N];
//struct Seg{
// int l, r, mid, val = 0, lazy_val = 0;
// Seg *lp, *rp;
// Seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
// if (l + 1 != r) {
// lp = new Seg(l, mid);
// rp = new Seg(mid, r);
// }
// }
// void push() {
// if (lazy_val) {
// lp->val = lp->lazy_val = lazy_val;
// rp->val = rp->lazy_val = lazy_val;
// }
// }
// void pull() {
// val = max(lp->val, rp->val);
// }
// int query(int a, int b) {
// if (a <= l && r <= b) return val;
// if (r <= a || b <= l) return 0;
// push();
// return max(lp->query(a, b), rp->query(a, b));
// }
// void update(int a, int b, int x) {
// if (a <= l && r <= b) {
// val = x;
// lazy_val = x;
// return;
// }
// if (r <= a || b <= l) return;
// push();
// lp->update(a, b, x), rp->update(a, b, x);
// pull();
// }
// int Count() {
// if (l + 1 == r) {
// return val == b[l];
// }
// push();
// return lp->Count() + rp->Count();
// }
//};
int n;
void update(int l, int r, vi &v) {
if (l > r) swap(l, r);
int x = 0;
for (int i = l; i <= r; i++) {
chkmax(x, v[i]);
}
for (int i = l; i <= r; i++) {
v[i] = x;
}
}
int Count(vi &v) {
int ans = 0;
for (int i = 0; i < n; i++) {
if (v[i] == b[i]) ans++;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vi a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
vi per(2 * n);
for (int i = 0; i < n; i++) per[i] = i;
for (int i = n; i < 2 * n; i++) per[i] = i - n;
int ans = 0;
do {
vi curr = a;
for (int i = 0; i < 2 * n; i += 2) {
update(per[i], per[i + 1], curr);
chkmax(ans, Count(curr));
}
} while (next_permutation(all(per)));
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
204 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
204 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
204 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |