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 <bits/stdc++.h>
using namespace std;
using mat = array<array<int, 3>, 3>;
const string alfa = "ATC";
int n;
vector<mat> prf;
void init(string a, string b) {
n = a.size();
prf.resize(n+1);
for (int i = 0; i < n; ++i) {
prf[i+1] = prf[i];
int ca = alfa.find(a[i]);
int cb = alfa.find(b[i]);
++prf[i+1][ca][cb];
}
}
int get_distance(int x, int y) {
mat m;
array<int, 3> sum_row{};
array<int, 3> sum_col{};
for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) {
m[i][j] = prf[y+1][i][j] - prf[x][i][j];
sum_row[i] += m[i][j];
sum_col[j] += m[i][j];
}
if (sum_row != sum_col) return -1;
int ans = 0;
for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) {
if (i == j) continue;
int v = min(m[i][j], m[j][i]);
ans += v;
m[i][j] -= v;
m[j][i] -= v;
}
ans += 2 * m[0][1];
ans += 2 * m[1][0];
return 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... |