#include "bits/stdc++.h"
#include "dna.h"
using namespace std;
vector<vector<int> > pre;
void init(string a, string b){
int n = a.size();
pre.resize(n+1);
for(int i = 0; i <= n; i++){
pre[i].resize(9);
}
for(int i = 0; i < n; i++){
int val = 0;
if(a[i] == 'T') val += 3;
else if(a[i] == 'C') val += 6;
if(b[i] == 'T') val += 1;
else if(b[i] == 'C') val += 2;
for(int j = 0; j < 9; j++){
pre[i+1][j] = pre[i][j];
}
pre[i+1][val]++;
}
}
int get_distance(int x, int y){
vector<int> cnt(9);
for(int i = 0; i < 9; i++){
cnt[i] = pre[y+1][i] - pre[x][i];
}
vector<int> tota(3), totb(3);
for(int i = 0; i < 9; i++){
tota[i/3] += cnt[i];
totb[i%3] += cnt[i];
}
if(tota[0] != totb[0] || tota[1] != totb[1] || tota[2] != totb[2]){
return -1;
}
int ans = 0;
cnt[0] = cnt[4] = cnt[8] = 0; // AA, TT, CC
int c1 = min(cnt[1], cnt[3]); // AT, TA
ans += c1;
cnt[1] -= c1;
cnt[3] -= c1;
int c2 = min(cnt[2], cnt[6]); // AC, CA
ans += c2;
cnt[2] -= c2;
cnt[6] -= c2;
int c3 = min(cnt[5], cnt[7]); // TC, CT
ans += c3;
cnt[5] -= c3;
cnt[7] -= c3;
int rem = 0;
for(int i = 0; i < 9; i++){
rem += cnt[i];
}
int add = (rem / 3) * 2;
ans += add;
return ans;
}
# | 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... |