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>
#include "dna.h"
using namespace std;
const int MAX_N = 1e5 + 10;
int preA[3][MAX_N], preB[3][MAX_N];
int preAB[3][3][MAX_N], preBA[3][3][MAX_N];
void init(string a, string b) {
map <char, int> mp;
mp['A'] = 0, mp['C'] = 1, mp['T'] = 2;
int N = a.length();
for(int i = 1; i <= N; i++) {
for(int j = 0; j < 3; j++) {
preA[j][i] = preA[j][i - 1];
preB[j][i] = preB[j][i - 1];
for(int k = 0; k < 3; k++) {
preAB[j][k][i] += preAB[j][k][i - 1];
preBA[j][k][i] += preBA[j][k][i - 1];
}
}
preA[mp[a[i - 1]]][i]++;
preB[mp[b[i - 1]]][i]++;
preAB[mp[a[i - 1]]][mp[b[i - 1]]][i]++;
preBA[mp[b[i - 1]]][mp[a[i - 1]]][i]++;
}
}
int range(int x, int y, int *a) {
return a[y + 1] - a[x];
}
int get_distance(int x, int y) {
for(int i = 0; i < 3; i++) {
if(range(x, y, preA[i]) != range(x, y, preB[i])) {
return -1;
}
}
int ans = 0, tmp = 0;
for(int i = 0; i < 3; i++) {
for(int j = i + 1; j < 3; j++) {
int L = range(x, y, preAB[i][j]), R = range(x, y, preBA[i][j]);
ans += min(L, R);
tmp += max(L, R) - min(L, R);
}
}
return ans + tmp * 2 / 3;
}
# | 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... |