# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552812 | Jomnoi | Mutating DNA (IOI21_dna) | C++17 | 0 ms | 0 KiB |
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 N;
int preTA[MAX_N], preAA[MAX_N];
int preTB[MAX_N], preAB[MAX_N];
int preTA[MAX_N], preAT[MAX_N];
void init(string a, string b) {
N = a.length();
for(int i = 1; i <= N; i++) {
preTA[i] = preTA[i - 1] + (a[i - 1] == 'T');
preTB[i] = preTB[i - 1] + (b[i - 1] == 'T');
preAA[i] = preAA[i - 1] + (a[i - 1] == 'A');
preAB[i] = preAB[i - 1] + (b[i - 1] == 'A');
preTA[i] = preTA[i - 1] + (a[i - 1] == 'T' and b[i - 1] == 'A');
preAT[i] = preAT[i - 1] + (a[i - 1] == 'A' and b[i - 1] == 'T');
}
}
int range(int x, int y, int *a) {
return a[y] - a[x - 1];
}
int get_distance(int x, int y) {
if(range(x, y, preTA) != range(x, y, preTB) or range(x, y, preAA) != range(x, y, preAB)) {
return -1;
}
return min(range(x, y, preTA), range(x, y, preAT));
}