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 <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int pref[N][3][3];
map<char, int> mp;
void init(string a, string b) {
mp['A'] = 0;
mp['C'] = 1;
mp['T'] = 2;
int n = (int) a.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
pref[i + 1][j][k] = pref[i][j][k] + (j == mp[a[i]] && k == mp[b[i]]);
}
}
}
}
int get_distance(int l, int r) {
vector<vector<int>> tmp(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
tmp[i][j] = pref[r + 1][i][j] - pref[l][i][j];
}
}
if (tmp[0][1] + tmp[0][2] != tmp[1][0] + tmp[2][0]) {
return -1;
}
if (tmp[1][0] + tmp[1][2] != tmp[0][1] + tmp[2][1]) {
return -1;
}
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
int mn = min(tmp[i][j], tmp[j][i]);
tmp[i][j] -= mn;
tmp[j][i] -= mn;
ans += mn;
}
}
int add = 1e9;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
add = min(add, max(tmp[i][j], tmp[j][i]));
}
}
return ans + add * 2;
}
# | 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... |