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 "dna.h"
#include<map>
using namespace std;
const int N = 123456;
int pref[3][3][N];
int asum[3][N];
int bsum[3][N];
map<char, int> f;
void init(std::string a, std::string b) {
f['A'] = 0; f['C'] = 1; f['T'] = 2;
int n = (int) a.size();
a = " " + a;
b = " " + b;
for (int i = 1; i <= n; i++) {
for (int k = 0; k < 3; k++) {
for (int l = 0; l < 3; l++) {
pref[k][l][i] = pref[k][l][i - 1] + (f[a[i]] == k && f[b[i]] == l);
}
asum[k][i] = asum[k][i - 1] + (f[a[i]] == k);
bsum[k][i] = bsum[k][i - 1] + (f[b[i]] == k);
}
}
}
int get_distance(int x, int y) {
x++; y++;
for (int t = 0; t < 3; t++) {
if (asum[t][y] - asum[t][x - 1] != bsum[t][y] - bsum[t][x - 1]) {
return -1;
}
}
int ans = 0, extra = 0;
for (int k = 0; k < 3; k++) {
for (int l = k + 1; l < 3; l++) {
ans += min(pref[k][l][y] - pref[k][l][x - 1], pref[l][k][y] - pref[l][k][x - 1]);
if (k == 0 and l == 1)
extra = abs((pref[k][l][y] - pref[k][l][x - 1]) - (pref[l][k][y] - pref[l][k][x - 1]));
}
}
return ans + 2 * extra;
}
# | 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... |