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 vala[100005];
long long valb[100005];
long long same[100005];
int AT[100005];
int TA[100005];
int AC[100005];
int CA[100005];
int TC[100005];
int CT[100005];
int aA[100005];
int aC[100005];
int aT[100005];
int bA[100005];
int bC[100005];
int bT[100005];
long long md=1e9+7;
void init(std::string a, std::string b) {
long long ta=0,tb=0;
for(int i=0;i<a.size();i++){
AT[i+1]=AT[i],TA[i+1]=TA[i],AC[i+1]=AC[i],CA[i+1]=CA[i],TC[i+1]=TC[i],CT[i+1]=CT[i];
if(a[i]=='A'&&b[i]=='T')AT[i+1]++;
else if(a[i]=='A'&&b[i]=='C')AC[i+1]++;
else if(a[i]=='T'&&b[i]=='A')TA[i+1]++;
else if(a[i]=='T'&&b[i]=='C')TC[i+1]++;
else if(a[i]=='C'&&b[i]=='A')CA[i+1]++;
else if(a[i]=='C'&&b[i]=='T')CT[i+1]++;
same[i+1]=same[i];
if(a[i]==b[i])same[i+1]++;
}
for(int i=0;i<a.size();i++){
aA[i+1]=aA[i],aC[i+1]=aC[i],aT[i+1]=aT[i];
bA[i+1]=bA[i],bC[i+1]=bC[i],bT[i+1]=bT[i];
if(a[i]=='A')aA[i+1]++;
else if(a[i]=='T')aT[i+1]++;
else aC[i+1]++;
if(b[i]=='A')bA[i+1]++;
else if(b[i]=='T')bT[i+1]++;
else bC[i+1]++;
}
}
int get_distance(int x, int y) {
x++,y++;
//cerr<<x<<" "<<y<<" "<<"info:\n";
//cerr<<aA[y]-aA[x-1]<<" "<<aT[y]-aT[x-1]<<"\n";
//cerr<<bA[y]-bA[x-1]<<" "<<bT[y]-bT[x-1]<<"\n";
//cerr<<"\n";
if(aA[y]-aA[x-1]!=bA[y]-bA[x-1])return -1;
if(aT[y]-aT[x-1]!=bT[y]-bT[x-1])return -1;
if(aC[y]-aC[x-1]!=bC[y]-bC[x-1])return -1;
int val=y-x+1-same[y]+same[x-1];
int ans=0;
ans+=min(TA[y]-TA[x-1],AT[y]-AT[x-1]);
ans+=min(TC[y]-TC[x-1],CT[y]-CT[x-1]);
ans+=min(AC[y]-AC[x-1],CA[y]-CA[x-1]);
int left=abs(TA[y]-TA[x-1]-(AT[y]-AT[x-1]))*2;
ans+=left;
//cerr<<"ans:\n";
//cerr<<y<<"-"<<x-1<<"-"<<same[y]<<"+"<<same[x-1]<<"\n";
return ans;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
dna.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
dna.cpp:22:15: warning: unused variable 'ta' [-Wunused-variable]
22 | long long ta=0,tb=0;
| ^~
dna.cpp:22:20: warning: unused variable 'tb' [-Wunused-variable]
22 | long long ta=0,tb=0;
| ^~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:57:9: warning: unused variable 'val' [-Wunused-variable]
57 | int val=y-x+1-same[y]+same[x-1];
| ^~~
# | 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... |