This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#define x first
#define y second
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 1e5 + 1;
int a[MAX_N], b[MAX_N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
int ans = a[0] == b[0];
for (int i = 1; i < n; i++) {
int count = a[i] == b[i];
int best_count = a[i] == b[i], ind = i;
for (int j = i - 1; j >= 0; j--) {
if (a[j] == b[j]) count--;
if (a[i] == b[j]) count++;
if (count > best_count) {
best_count = count;
ind = j;
}
}
for (int j = i - 1; j >= ind; j--) a[j] = a[i];
ans += best_count;
}
cout << ans;
}
# | 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... |