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 <map>
#include <vector>
const int MAXN = 1e5 + 5;
std::vector<std::map<char, int>> aDP(MAXN);
std::vector<std::map<char, int>> bDP(MAXN);
std::vector<std::map<char, std::map<char, int>>> abDP(MAXN);
void init(std::string a, std::string b) {
for (int i = 0; i < (int) a.length(); ++i)
{
aDP[i + 1] = aDP[i];
bDP[i + 1] = bDP[i];
abDP[i + 1] = abDP[i];
abDP[i + 1][a[i]][b[i]]++;
if (a[i] != b[i])
{
aDP[i + 1][a[i]]++;
bDP[i + 1][b[i]]++;
}
}
}
int get_distance(int x, int y) {
y++;
int aAcumA = aDP[y]['A'] - aDP[x]['A'];
int aAcumC = aDP[y]['C'] - aDP[x]['C'];
int aAcumT = aDP[y]['T'] - aDP[x]['T'];
int bAcumA = bDP[y]['A'] - bDP[x]['A'];
int bAcumC = bDP[y]['C'] - bDP[x]['C'];
int bAcumT = bDP[y]['T'] - bDP[x]['T'];
if (aAcumA != bAcumA || aAcumC != bAcumC || aAcumT != bAcumT) return -1;
std::map<char, std::map<char, int>> comb;
comb['A']['C'] = abDP[y]['A']['C'] - abDP[x]['A']['C'];
comb['C']['A'] = abDP[y]['C']['A'] - abDP[x]['C']['A'];
comb['A']['T'] = abDP[y]['A']['T'] - abDP[x]['A']['T'];
comb['T']['A'] = abDP[y]['T']['A'] - abDP[x]['T']['A'];
comb['C']['T'] = abDP[y]['C']['T'] - abDP[x]['C']['T'];
comb['T']['C'] = abDP[y]['T']['C'] - abDP[x]['T']['C'];
int distance = 0;
distance += std::min(comb['A']['C'], comb['C']['A']);
distance += std::min(comb['A']['T'], comb['T']['A']);
distance += std::min(comb['C']['T'], comb['T']['C']);
distance += std::abs(comb['A']['T'] - comb['T']['A']) << 1;
return distance;
}
# | 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... |