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>
using namespace std;
//#include "dna.h"
int n,C[4][4][100003];
void init(string a, string b) {
n = a.size();
for(int i = 0; i < n; i++){
if((a[i]=='A')and(b[i]=='A')) C[1][1][i+1] = C[1][1][i]+1;
else C[1][1][i+1] = C[1][1][i];
if((a[i]=='T')and(b[i]=='T')) C[2][2][i+1] = C[2][2][i]+1;
else C[2][2][i+1] = C[2][2][i];
if((a[i]=='C')and(b[i]=='C')) C[3][3][i+1] = C[3][3][i]+1;
else C[3][3][i+1] = C[3][3][i];
if((a[i]=='A')and(b[i]=='T')) C[1][2][i+1] = C[1][2][i]+1;
else C[1][2][i+1] = C[1][2][i];
if((a[i]=='A')and(b[i]=='C')) C[1][3][i+1] = C[1][3][i]+1;
else C[1][3][i+1] = C[1][3][i];
if((a[i]=='T')and(b[i]=='A')) C[2][1][i+1] = C[2][1][i]+1;
else C[2][1][i+1] = C[2][1][i];
if((a[i]=='T')and(b[i]=='C')) C[2][3][i+1] = C[2][3][i]+1;
else C[2][3][i+1] = C[2][3][i];
if((a[i]=='C')and(b[i]=='A')) C[3][1][i+1] = C[3][1][i]+1;
else C[3][1][i+1] = C[3][1][i];
if((a[i]=='C')and(b[i]=='T')) C[3][2][i+1] = C[3][2][i]+1;
else C[3][2][i+1] = C[3][2][i];
}
}
int get_distance(int x, int y) {
int sol = 0,xa,ya,z;
xa = C[1][1][n]+C[1][2][n]+C[1][3][n];
ya = C[2][1][n]+C[2][2][n]+C[2][3][n];
z = C[3][1][n]+C[3][2][n]+C[3][3][n];
if((xa==n)and(ya==n)and(z==n)){
sol = min(C[1][2][y+1]-C[1][2][x],C[2][1][y+1]-C[2][1][x]);
sol += min(C[1][3][y+1]-C[1][3][x],C[3][1][y+1]-C[3][1][x]);
sol += min(C[3][2][y+1]-C[3][2][x],C[2][3][y+1]-C[2][3][x]);
sol += 2*(max(C[1][2][y+1]-C[1][2][x],C[2][1][y+1]-C[2][1][x])-min(C[1][2][y+1]-C[1][2][x],C[2][1][y+1]-C[2][1][x]));
}
else sol = -1;
return sol;
}
# | 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... |