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>
//using namespace std;
std::vector<std::map<char, int>> aDP;
std::vector<std::map<char, int>> bDP;
void init(std::string a, std::string b) {
std::vector<std::map<char, int>> aux(a.length() + 1);
aDP = aux;
bDP = aux;
aDP[0]['A'] = 0;
aDP[0]['C'] = 0;
aDP[0]['T'] = 0;
bDP[0]['A'] = 0;
bDP[0]['C'] = 0;
bDP[0]['T'] = 0;
if (a[0] != b[0]) {
aDP[1][a[0]]++;
bDP[1][b[0]]++;
}
for (int i = 1; i < (int) a.length(); ++i)
{
aDP[i + 1] = aDP[i];
bDP[i + 1] = bDP[i];
if (a[i] != b[i])
{
aDP[i + 1][a[i]]++;
bDP[i + 1][b[i]]++;
}
}
}
int get_distance(int x, int y) {
//if (x > 1) x--;
//if (y > 1) 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'];
// printf("x: %i\ny: %i\n", x, y);
// printf("aDP[y]['A']: %i\n", aDP[y]['A']);
// printf("aDP[y]['C']: %i\n", aDP[y]['C']);
// printf("aDP[y]['T']: %i\n", aDP[y]['T']);
// printf("aDP[x]['A']: %i\n", aDP[x]['A']);
// printf("aDP[x]['C']: %i\n", aDP[x]['C']);
// printf("aDP[x]['T']: %i\n", aDP[x]['T']);
// printf("bDP[y]['A']: %i\n", bDP[y]['A']);
// printf("bDP[y]['C']: %i\n", bDP[y]['C']);
// printf("bDP[y]['T']: %i\n", bDP[y]['T']);
// printf("bDP[x]['A']: %i\n", bDP[x]['A']);
// printf("bDP[x]['C']: %i\n", bDP[x]['C']);
// printf("bDP[x]['T']: %i\n", bDP[x]['T']);
// printf("aAcumA: %i\n", aAcumA);
// printf("aAcumC: %i\n", aAcumC);
// printf("aAcumT: %i\n", aAcumT);
// printf("bAcumA: %i\n", bAcumA);
// printf("bAcumC: %i\n", bAcumC);
// printf("bAcumT: %i\n", bAcumT);
// printf("\n");
if (aAcumA != bAcumA || aAcumC != bAcumC || aAcumT != bAcumT) return -1;
int total = aAcumA + aAcumC + aAcumT;
int moves = total >> 1;
// printf("Total: %i\n", total);
return (total & 1) ? moves + 1 : moves;
}
# | 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... |