#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
string a, b;
void init(std::string _a, std::string _b) {
a = _a;
b = _b;
mp['A'] = 0;
mp['T'] = 1;
mp['C'] = 2;
}
// 1, 2, 4
// 8, 16, 32
int get_distance(int x, int y) {
vector<vector<int>> cnt(3, vector<int>(3));
vector<int> bal(3);
int res = 0;
int left = y - x + 1;
for (int i = x; i <= y; ++i) {
int ai = mp[a[i]];
int bi = mp[b[i]];
if (ai == bi) {
left -= 1;
continue;
}
cnt[ai][bi] += 1;
bal[ai] += 1;
bal[bi] -= 1;
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
int take = min(cnt[i][j], cnt[j][i]);
cnt[i][j] -= take;
cnt[j][i] -= take;
left -= 2 * take;
res += take;
}
}
for (auto& i : bal) {
if (i != 0) return -1;
}
// cerr << "[" << a.substr(x, y - x + 1) << " , " << b.substr(x, y - x + 1) << "] = " << res << "\n";
// assert(res % 2 == 0);
// cerr << left << "\n";
assert(left % 3 == 0);
return res + (left / 3) * 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... |