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"
const int mxN=100010;
int N;
int A[mxN][2], B[mxN][6];
int S[mxN][3][2];
int T[mxN][6];
void init(std::string a, std::string b) {
N=a.size();
for(int i=0;i<N;i++)
{
if(a[i]=='A') A[i+1][0]=0;
if(a[i]=='T') A[i+1][0]=1;
if(a[i]=='C') A[i+1][0]=2;
if(b[i]=='A') A[i+1][1]=0;
if(b[i]=='T') A[i+1][1]=1;
if(b[i]=='C') A[i+1][1]=2;
}
for(int i=1;i<=N;i++)
{
int idx=0;
for(int j=0;j<3;j++)
{
for(int k=0;k<3;k++)
{
if(j==k) continue;
if(A[i][0]==j && A[i][1]==k) B[i][idx]++;
idx++;
}
}
}
for(int i=1;i<=N;i++)
{
for(int j=0;j<3;j++)
{
S[i][j][0]=S[i-1][j][0]+(A[i][0]==j ? 1 : 0);
S[i][j][1]=S[i-1][j][1]+(A[i][1]==j ? 1 : 0);
}
for(int j=0;j<6;j++)
{
T[i][j]=T[i-1][j]+B[i][j];
}
}
}
int get_distance(int x, int y) {
x++; y++;
for(int i=0;i<3;i++)
{
if(S[y][i][0]-S[x-1][i][0]!=S[y][i][1]-S[x-1][i][1]) return -1;
}
int ans=0;
int arr[6], tmp;
for(int i=0;i<6;i++) arr[i]=T[y][i]-T[x-1][i];
ans+=min(arr[0], arr[2]);
ans+=min(arr[1], arr[4]);
ans+=min(arr[3], arr[5]);
tmp=min(arr[0], arr[2]);
arr[0]-=tmp; arr[2]-=tmp;
tmp=min(arr[1], arr[4]);
arr[1]-=tmp; arr[4]-=tmp;
tmp=min(arr[3], arr[5]);
arr[3]-=tmp; arr[5]-=tmp;
if(arr[0]!=0) ans+=2*arr[0];
else ans+=2*arr[2];
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... |