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;
int n,ct[100005][5],ct2[100005][5],pp[100005][15],num,num2;
string t[15]={"AC","CA","AT","TA","TC","CT","AA","CC","TT"};
char s[8]={'A','C','T'};
void init(std::string a, std::string b) {
n=a.length();
for (int i=0;i<n;i++){
for (int j=0;j<3;j++){
if (i != 0){
ct[i][j]=ct[i-1][j];
ct2[i][j]=ct2[i-1][j];
}
if (a[i] == s[j])
ct[i][j]++;
if (b[i] == s[j])
ct2[i][j]++;
}
for (int j=0;j<9;j++){
if (i != 0)
pp[i][j]=pp[i-1][j];
if (a[i] == t[j][0] && b[i] == t[j][1])
pp[i][j]++;
}
}
}
int get_distance(int x, int y) {
for (int i=0;i<3;i++){
if (x == 0){
if (ct[y][i] != ct2[y][i])
return -1;
}
else
if (ct[y][i]-ct[x-1][i] != ct2[y][i]-ct2[x-1][i])
return -1;
}
if (x == 0){
num=min(pp[y][0],pp[y][1])+min(pp[y][2],pp[y][3])+min(pp[y][4],pp[y][5]);
num2=pp[y][6]+pp[y][7]+pp[y][8];
return num+max(1,y-x+1-num*2-num2)-1;
}
else
{
num=min(pp[y][0]-pp[x-1][0],pp[y][1]-pp[x-1][1])+min(pp[y][2]-pp[x-1][2],pp[y][3]-pp[x-1][3])+min(pp[y][4]-pp[x-1][4],pp[y][5]-pp[x-1][5]);
num2=pp[y][6]-pp[x-1][6]+pp[y][7]-pp[x-1][7]+pp[y][8]-pp[x-1][8];
return num+max(1,y-x+1-num*2-num2)-1;
}
}
/*
string r,g;
int aa,bb;
int main(){
cin >> r >> g;
init(r,g);
for (int i=1;i<=4;i++){
cin >> aa >> bb;
cout << get_distance(aa,bb) << "\n";
}
}*/
# | 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... |