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;
long long s[100002][8], pref[100002][4], pref2[100002][4];
void init(std::string a, std::string b) {
long long i,j;
for(i=0;i<a.size();i++)
{
if(a[i]=='A' && b[i]=='T')s[i][1]++;
if(a[i]=='T' && b[i]=='A')s[i][2]++;
if(a[i]=='C' && b[i]=='T')s[i][3]++;
if(a[i]=='T' && b[i]=='C')s[i][4]++;
if(a[i]=='A' && b[i]=='C')s[i][5]++;
if(a[i]=='C' && b[i]=='A')s[i][6]++;
if(i!=0)for(j=1;j<=6;j++)s[i][j]+=s[i-1][j];
if(a[i]=='A')pref[i][1]++;
if(a[i]=='T')pref[i][2]++;
if(a[i]=='C')pref[i][3]++;
if(i!=0)for(j=1;j<=3;j++)pref[i][j]+=pref[i-1][j];
if(b[i]=='A')pref2[i][1]++;
if(b[i]=='T')pref2[i][2]++;
if(b[i]=='C')pref2[i][3]++;
if(i!=0)for(j=1;j<=3;j++)pref2[i][j]+=pref2[i-1][j];
}
}
int get_distance(int x, int y) {
long long A=pref[y][1], A2=pref2[y][1];
if(x>0){A-=pref[x-1][1]; A2-=pref2[x-1][1];}
long long B=pref[y][2], B2=pref2[y][2];
if(x>0){B-=pref[x-1][2]; B2-=pref2[x-1][2];}
long long C=pref[y][3], C2=pref2[y][3];
if(x>0){C-=pref[x-1][3]; C2-=pref2[x-1][3];}
if((A!=A2) || (B!=B2 )||(C!=C2))return -1;
long long AT = s[y][1]-(x>0?s[x-1][1]:0);
long long TA = s[y][2]-(x>0?s[x-1][2]:0);
long long CT = s[y][3]-(x>0?s[x-1][3]:0);
long long TC = s[y][4]-(x>0?s[x-1][4]:0);
long long AC = s[y][5]-(x>0?s[x-1][5]:0);
long long CA = s[y][6]-(x>0?s[x-1][6]:0);
long long ans=0;
ans+=min(AT,TA)+min(CT,TC)+min(AC,CA);
AT-=TA;
if(AT<0)AT=-AT;
ans+=2*AT;
return ans;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:9:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for(i=0;i<a.size();i++)
| ~^~~~~~~~~
# | 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... |