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<string>
//#include<iostream>
using namespace std;
string s_a, s_b;
class DNA{
public:
string str_{};
int A_count{0}, T_count{0}, C_count{0};
DNA (string a) : str_(a) {
for (auto i: str_){
switch((int)i){
case 65:
this->A_count++;
break;
case 67:
this->C_count++;
break;
case 84:
this->T_count++;
break;
default:
break;
}}}
};
void init(string a, string b){
s_a=a;
s_b=b;
}
int get_distance(int x, int y){
// Feasible Check
const int len{(y-x)+1};
DNA a_sub{s_a.substr((long long unsigned int)x, (long long unsigned int)len)};
DNA b_sub{s_b.substr((long long unsigned int)x, (long long unsigned int)len)};
if ((a_sub.A_count != b_sub.A_count) or (a_sub.C_count != b_sub.C_count) or (a_sub.T_count != b_sub.T_count)) return -1;
// Greedy Algorithm
int r{0}, i{0};
for( auto j : a_sub.str_){
char b_i = b_sub.str_.at((long long unsigned int)i);
if (b_i != j)
{
for (int k{i+1}; k<len; k++){
if (b_sub.str_.at((long long unsigned int)k) == j)
{
b_sub.str_[(long long unsigned int)i] = j;
b_sub.str_[(long long unsigned int)k] = b_i;
r++;
break;
}
}
}
i++;
}
return r;
}
/*
int main(){
string str1, str2;
int a,b;
cin >> str1 >> str2;
init(str1, str2);
cin >> a >> b;
cout << get_distance(a,b);
return 0;
}*/
# | 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... |