#include "dna.h"
#include <vector>
#include <iostream>
#include <unordered_map>
#define N 100001
using namespace std;
vector <int> s1;
vector <int> s2;
unordered_map <char,int> convert;
bool st2 = true;
void init(std::string a, std::string b) {
st2 = true;
convert['A'] = 0;
convert['C'] = 1;
convert['T'] = 2;
for (int i = 0; i < a.size(); ++i){
if (a[i] == 'C' || b[i] == 'C'){
st2 = false;
}
s1.push_back(convert[a[i]]);
s2.push_back(convert[b[i]]);
}
}
int get_distance(int x, int y) {
vector<int>section1;
vector<int>section2;
int num1A = 0;
int num1T = 0;
int num2A = 0;
int num2T = 0;
if (!st2){
vector<int> occ1(3,0);
vector<int> occ2(3,0);
for (int i = x; i <= y; ++i){
occ1[s1[i]]++;
section1.push_back(s1[i]);
}
for (int i = x; i <= y; ++i){
occ2[s2[i]]++;
section2.push_back(s2[i]);
}
if (occ1 != occ2){
return -1;
}
if (section1 == section2){
return 0;
}
swap(section1[0], section1[1]);
if (section1 == section2){
return 1;
}
swap(section1[0], section1[1]);
swap(section1[1], section1[2]);
if (section1 == section2){
return 1;
}
swap(section1[1], section1[2]);
swap(section1[0], section1[2]);
if (section1 == section2){
return 1;
}
swap(section1[0], section1[2]);
return 2;
}else{
section1.resize(0);
section2.resize(0);
for (int i = x; i <= y; ++i){
num1A += (s1[i] == 0);
num2A += (s2[i] == 0);
if (s1[i] != s2[i]){
section1.push_back(s1[i]);
section2.push_back(s2[i]);
}
}
// for(int i: section1){
// cout<<i<<' ';
// }
// cout<<"size "<<section1.size()<<endl;
if (num1A != num2A){
return -1;
}else{
return (int)section1.size()/2;
}
}
}
# | 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... |