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>
#define ll long long
#define MAXN 100010
using namespace std;
int AC[MAXN],CA[MAXN],CT[MAXN],TC[MAXN],TA[MAXN],AT[MAXN],cnt[5][5][MAXN];
void init(string a, string b)
{
int n=a.size();
a=' '+a;
b=' '+b;
for (ll i=1;i<=n;i++)
{
for (ll j=1;j<=3;j++)
{
for (ll l=1;l<=2;l++)
cnt[j][l][i]=cnt[j][l][i-1];
}
if (a[i]=='A')
cnt[1][1][i]++;
else if (a[i]=='C')
cnt[2][1][i]++;
else
cnt[3][1][i]++;
if (b[i]=='A')
cnt[1][2][i]++;
else if (b[i]=='C')
cnt[2][2][i]++;
else
cnt[3][2][i]++;
AC[i]=AC[i-1];
CA[i]=CA[i-1];
CT[i]=CT[i-1];
TC[i]=TC[i-1];
TA[i]=TA[i-1];
AT[i]=AT[i-1];
if (a[i]=='A' && b[i]=='C')
AC[i]++;
else if (a[i]=='C' && b[i]=='A')
CA[i]++;
else if (a[i]=='C' && b[i]=='T')
CT[i]++;
else if (a[i]=='T' && b[i]=='C')
TC[i]++;
else if (a[i]=='T' && b[i]=='A')
TA[i]++;
else if (a[i]=='A' && b[i]=='T')
AT[i]++;
}
}
int get_distance(int x, int y)
{
x++;
y++;
if (cnt[1][1][y]-cnt[1][1][x-1]!=cnt[1][2][y]-cnt[1][2][x-1] || cnt[2][1][y]-cnt[2][1][x-1]!=cnt[2][2][y]-cnt[2][2][x-1] || cnt[3][1][y]-cnt[3][1][x-1]!=cnt[3][2][y]-cnt[3][2][x-1])
return -1;
int curAC=AC[y]-AC[x-1],curCA=CA[y]-CA[x-1],curCT=CT[y]-CT[x-1],curTC=TC[y]-TC[x-1],curTA=TA[y]-TA[x-1],curAT=AT[y]-AT[x-1];
int minn=min(curAC,curCA),ans=0;
curAC-=minn;
curCA-=minn;
ans+=minn;
minn=min(curCT,curTC);
curCT-=minn;
curTC-=minn;
ans+=minn;
minn=min(curTA,curAT);
curTA-=minn;
curAT-=minn;
ans+=minn;
return ans+max(curAC,curCA)+max(curCT,curTC)+max(curTA,curAT)-max({max(curAC,curCA),max(curCT,curTC),max(curTA,curAT)});
}
# | 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... |