# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
558554 | pawned | Mutating DNA (IOI21_dna) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
void init(std::string a, std::string b) {
int N = a.size();
int pfs1[N + 1][3];
pfs1[0][0] = 0;
pfs1[0][1] = 0;
pfs1[0][2] = 0;
int pfs2[N + 1][3];
pfs2[0][0] = 0;
pfs2[0][1] = 0;
pfs2[0][2] = 0;
for (int i = 1; i <= N; i++) {
if (a[i - 1] == 'A')
pfs1[i][0] = pfs1[i - 1][0] + 1;
if (a[i - 1] == 'T')
pfs1[i][1] = pfs1[i - 1][1] + 1;
if (a[i - 1] == 'C')
pfs1[i][2] = pfs1[i - 1][2] + 1;
if (b[i - 1] == 'A')
pfs2[i][0] = pfs2[i - 1][0] + 1;
if (b[i - 1] == 'T')
pfs2[i][1] = pfs2[i - 1][1] + 1;
if (b[i - 1] == 'C')
pfs2[i][2] = pfs2[i - 1][2] + 1;
}
int pfs[N + 1];
pfs[0] = 0;
for (int i = 1; i <= N; i++) {
pfs[i] = pfs[i - 1];
if (a[i - 1] != b[i - 1])
pfs[i]++;
}
}
int get_distance(int x, int y) {
bool works = true;
for (int i = 0; i < 3; i++) {
if (pfs1[y][i] - pfs[x - 1][i] != pfs2[y][i] - pfs2[x - 1][i])
works = false;
}
if (!works)
return -1;
else
return (pfs[y] - pfs[x - 1]);
}