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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> as, bs;
vector<vector<vector<int>>> p;
void init(std::string a, std::string b) {
int n = a.size();
for (int i = 0; i < n; i++)
{
if (a[i] == 'T')
a[i] = 'B';
if (b[i] == 'T')
b[i] = 'B';
}
p.resize(n + 1, vector<vector<int>> (3, vector<int> (3)));
as.resize(n + 1, vector<int>(3));
bs.resize(n + 1, vector<int>(3));
for (int i = 0; i < n; i++)
{
as[i + 1] = as[i];
as[i + 1][a[i] - 'A']++;
bs[i + 1] = bs[i];
bs[i + 1][b[i] - 'A']++;
p[i + 1] = p[i];
p[i + 1][b[i] - 'A'][a[i] - 'A']++;
}
}
int get_distance(int x, int y) {
x ++;
y ++;
if (as[y][0] - as[x - 1][0] == bs[y][0] - bs[x - 1][0] && as[y][1] - as[x - 1][1] == bs[y][1] - bs[x - 1][1] && as[y][2] - as[x - 1][2] == bs[y][2] - bs[x - 1][2])
{
int k = y - x + 1, ans = 0;
for (int i = 0; i < 3; i++){
k -= p[y][i][i] - p[x - 1][i][i];
for (int j = i + 1; j < 3; j++){
ans += min(p[y][i][j] - p[x - 1][i][j], p[y][j][i] - p[x - 1][j][i]);
k -= 2 * min(p[y][i][j] - p[x - 1][i][j], p[y][j][i] - p[x - 1][j][i]);
}
}
ans += k - 1;
return ans;
}
return -1;
}
# | 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... |