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 pre[100010][3], pre2[100010][3], pre3[100010][6], i, j, n;
void init(string a, string b)
{
n=a.size();
for(i=0;i<n;i++)
{
if(a[i]=='A')pre[i][0]++;
if(a[i]=='T')pre[i][1]++;
if(a[i]=='C')pre[i][2]++;
}
for(i=0;i<n;i++)
{
if(b[i]=='A')pre2[i][0]++;
if(b[i]=='T')pre2[i][1]++;
if(b[i]=='C')pre2[i][2]++;
}
for(i=1;i<n;i++)for(j=0;j<3;j++)pre[i][j]+=pre[i-1][j],pre2[i][j]+=pre2[i-1][j];
for(i=0;i<n;i++)
{
if(a[i]=='A'&&b[i]=='T')pre3[i][0]++;
if(a[i]=='A'&&b[i]=='C')pre3[i][1]++;
if(a[i]=='T'&&b[i]=='A')pre3[i][2]++;
if(a[i]=='T'&&b[i]=='C')pre3[i][3]++;
if(a[i]=='C'&&b[i]=='A')pre3[i][4]++;
if(a[i]=='C'&&b[i]=='T')pre3[i][5]++;
}
for(i=1;i<n;i++)for(j=0;j<6;j++)pre3[i][j]+=pre3[i-1][j];
}
int get_distance(int x, int y)
{
int ans=0;
for(i=0;i<3;i++)if(pre[y][i]-(x==0?0:pre[x-1][i])!=pre2[y][i]-(x==0?0:pre2[x-1][i]))return -1;
int A[6]={};
for(i=0;i<6;i++)A[i]=pre3[y][i]-(x==0?0:pre3[x-1][i]);
int a=min(A[0], A[2]);ans+=a;A[0]-=a;A[2]-=a;
a=min(A[1], A[4]);ans+=a;A[1]-=a;A[4]-=a;
a=min(A[3], A[5]);ans+=a;A[3]-=a;A[5]-=a;
a=0;for(i=0;i<6;i++)a+=A[i];ans+=(2*a)/3;
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... |