# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441077 | lalafa | Mutating DNA (IOI21_dna) | C++17 | 43 ms | 5608 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 <string>
#include <algorithm>
std::vector<int>ccc;
void init(std::string a, std::string b) {
auto v = [](char c) { return c == 'A' ? 0 : c == 'C' ? 1 : 2; };
ccc.resize(a.size() * 9 + 10, 0);
for (int i = 0; i < a.size(); ++i) {
for(int j = 0; j < 9; ++j) ccc[i*9 + j + 9] = ccc[i*9 + j];
int v9 = v(a[i]) * 3 + v(b[i]);
ccc[i*9 +v9 + 9] = ccc[i*9 + v9];
}
}
int get_distance(int x, int y) {
int c[3] = {0,0,0};
int cc[3][3];
for (int i = 0; i <9 ; ++i) {
int v = ccc[y*9 + 9 + i] - ccc[x*9 + i];
cc[i/3][i%3] = v;
c[i/3] += v;
c[i%3] -= v;
}
if (c[0] != 0 || c[1] != 0 || c[2] != 0) return -1;
int res = 0, mv = 0;
for (int v0 = 0; v0 < 2; ++v0) {
for (int v1 = v0 + 1; v1 < 3; ++v1) {
int vlo = std::min(cc[v0][v1], cc[v1][v0]);
int vhi = std::max(cc[v0][v1], cc[v1][v0]);
res += vlo;
mv = std::max(mv, vhi - vlo);
}
}
return res + 2 * mv;
}
Compilation message (stderr)
# | 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... |