# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705487 | jakobrs | 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.
#include <xmmintrin.h>
#include <iostream>
#include <vector>
union Count {
__m128i simd;
struct {
int at, ca, tc;
int qw;
};
inline Count operator-(Count rhs) const {
return Count{.simd = _mm_sub_epi32(simd, rhs.simd)};
}
};
std::string a, b;
std::vector<Count> prefixes;
void init(std::string A, std::string B) {
a = A;
b = B;
prefixes.reserve(A.size() + 1);
prefixes.push_back(Count{});
Count count{.at = 0, .ca = 0, .tc = 0, .qw = 0};
for (int i = 0; i < A.size(); i++) {
if (A[i] == 'A' && B[i] == 'T') count.at += 1;
if (A[i] == 'T' && B[i] == 'A') count.at -= 1;
if (A[i] == 'C' && B[i] == 'A') count.ca += 1;
if (A[i] == 'A' && B[i] == 'C') count.ca -= 1;
if (A[i] == 'T' && B[i] == 'C') count.tc += 1;
if (A[i] == 'C' && B[i] == 'T') count.tc -= 1;
if (A[i] != B[i]) count.qw += 1;
prefixes.push_back(count);
}
}
int get_distance(int x, int y) {
y += 1;
Count count = prefixes[y] - prefixes[x];
if (!(count.at == count.ca && count.ca == count.tc)) return -1;
int total =
count.qw - std::abs(count.at) - std::abs(count.tc) - std::abs(count.ca);
total /= 2;
return total + std::abs(count.at) * 2;
}