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"
#include "dna.h"
using namespace std;
string a,b;
void init(std::string A, std::string B) {
a=A;
b=B;
}
void count(int &res, int &f, int &s){
res+=f;
s-=f;
f=0;
}
int get_distance(int x, int y) {
int canta[26]={};
int cantb[26]={};
int n=a.size();
for(int i=x;i<=y;i++){
canta[a[i]-'A']++;
cantb[b[i]-'A']++;
}
for(int i=0;i<26;i++)
if(canta[i]!=cantb[i]) return -1;
int ac,at,ct=ac=at=0;
int ca,ta,tc=ca=ta=0;
for(int i=x;i<=y;i++){
if(a[i]=='A' && b[i]=='C') ac++;
if(a[i]=='A' && b[i]=='T') at++;
if(a[i]=='C' && b[i]=='T') ct++;
if(a[i]=='C' && b[i]=='A') ca++;
if(a[i]=='T' && b[i]=='A') ta++;
if(a[i]=='T' && b[i]=='C') tc++;
}
//printf("\nbefore\n");
//printf("ac = %d | ca = %d\n",ac,ca);
//printf("at = %d | ta = %d\n",at,ta);
//printf("tc = %d | ct = %d\n",tc,ct);
int res=0;
(ac<ca) ? count(res,ac,ca) : count(res,ca,ac);
(at<ta) ? count(res,at,ta) : count(res,ta,at);
(tc<ct) ? count(res,tc,ct) : count(res,ct,tc);
//printf("\nafter\n");
//printf("ac = %d | ca = %d\n",ac,ca);
//printf("at = %d | ta = %d\n",at,ta);
//printf("tc = %d | ct = %d\n",tc,ct);
//printf("res at the ''end'' --> %d\n",res);
ac=max(ac,ca);
at=max(at,ta);
tc=max(tc,ct);
res+=ac+at;
return res;
}
Compilation message (stderr)
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:21:6: warning: unused variable 'n' [-Wunused-variable]
21 | int n=a.size();
| ^
# | 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... |