이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |