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 <algorithm>
#include <iostream>
using namespace std;
const int N = 1e5+5;
int p[3][3][N];
int GN;
void init(std::string a, std::string b) {
GN = a.length();
for(char& c : a)
{
if(c == 'T')
c = 'B';
}
for(char& c : b)
{
if(c == 'T')
c = 'B';
}
for(int i = 0; i < GN; i++)
{
int c1 = a[i]-'A';
int c2 = b[i]-'A';
for(int k1 = 0; k1 < 3; k1++)
for(int k2 = 0; k2 < 3; k2++)
{
p[k1][k2][i+1] = p[k1][k2][i] + (c1 == k1)*(c2 == k2);
}
}
}
int get_distance(int x, int y) {
x++, y++;
int ab, bc, ca, ba, ac, cb;
int aa = p[0][0][y]-p[0][0][x-1];
int bb = p[1][1][y]-p[1][1][x-1];
int cc = p[2][2][y]-p[2][2][x-1];
ab = p[0][1][y]-p[0][1][x-1];
bc = p[1][2][y]-p[1][2][x-1];
ca = p[2][0][y]-p[2][0][x-1];
ba = p[1][0][y]-p[1][0][x-1];
ac = p[0][2][y]-p[0][2][x-1];
cb = p[2][1][y]-p[2][1][x-1];
//cerr << ab << bc << ca << ba << ac << cb << '\n';
if(ab+ac != ba+ca ||
bc+ba != ab+cb ||
ca+cb != ac+bc)
return -1;
int tt = min(ab, ba)+min(bc, cb)+min(ca, ac);
return tt+(y-x+1-tt*2-aa-bb-cc)*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... |