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 <iostream>
#include<map>
//#include<pair>
using namespace std;
string s="",c="";
map<pair<char,char>,int>m;
void init(string a, string b) {
s=a;
c=b; int n=s.size();
}
int get_distance(int x, int y) {
m[{'C','T'}]=0;
m[{'T','C'}]=0;
m[{'A','T'}]=0;
m[{'T','A'}]=0;
m[{'C','A'}]=0;
m[{'A','C'}]=0;
int A=0,C=0,T=0,A2=0,C2=0,T2=0; int ans=0;
for(int i=x;i<=y;i++)
{
if(s[i]!=c[i])
{
m[{s[i],c[i]}]++; ans++;
}
if(s[i]=='A') A++;
if(s[i]=='T') T++;
if(s[i]=='C') C++;
if(c[i]=='A') A2++;
if(c[i]=='T') T2++;
if(c[i]=='C') C2++;
} int we=0;
if(A!=A2||C!=C2||T!=T2)
return -1;
else
{
int mn=min(m[{'A','T'}],m[{'T','A'}]); // cout<<" "<<mn<<endl;
ans-=mn*2; we+=mn; m[{'A','T'}]-=mn; m[{'T','A'}]-=mn;
mn=min(m[{'A','C'}],m[{'C','A'}]); //cout<<" "<<mn<<endl;
ans-=mn*2; we+=mn; m[{'A','C'}]-=mn; m[{'C','A'}]-=mn;
mn=min(m[{'T','C'}],m[{'C','T'}]); // cout<<" "<<mn<<endl;
m[{'T','C'}]-=mn; m[{'C','T'}]-=mn; //cout<<endl; cout<<endl;
ans-=mn*2; we+=mn;
int h=m[{'A','T'}];
h=max(h,m[{'T','A'}]);
h=max(h,m[{'A','C'}]);
h=max(h,m[{'C','A'}]);
h=max(h,m[{'T','C'}]);
h=max(h,m[{'C','T'}]);
we+=h*2;
} m.clear();
return we;
return 0;
}
// ATCTCAA TATCATC
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:10:15: warning: unused variable 'n' [-Wunused-variable]
10 | c=b; int n=s.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... |