# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636747 | imeimi2000 | Mutating DNA (IOI21_dna) | C++17 | 41 ms | 7364 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 "dna.h"
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int cnt[100005][3][3];
void init(string a, string b) {
n = a.size();
int C[256];
C['A'] = 0;
C['C'] = 1;
C['T'] = 2;
for (int i = 1; i <= n; ++i) {
memcpy(cnt[i], cnt[i - 1], sizeof(cnt[i]));
++cnt[i][C[a[i - 1]]][C[b[i - 1]]];
}
}
int get_distance(int x, int y) {
int D[3][3];
memcpy(D, cnt[y + 1], sizeof(D));
for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) D[i][j] -= cnt[x][i][j];
int ans = 0;
for (int i = 0; i < 3; ++i) {
for (int j = i + 1; j < 3; ++j) {
int v = min(D[i][j], D[j][i]);
ans += v;
D[i][j] -= v;
D[j][i] -= v;
}
}
int v = min({ D[0][1], D[1][2], D[2][0] });
D[0][1] -= v;
D[1][2] -= v;
D[2][0] -= v;
ans += v + v;
v = min({ D[1][0], D[2][1], D[0][2] });
D[1][0] -= v;
D[2][1] -= v;
D[0][2] -= v;
ans += v + v;
for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) if (i != j && D[i][j]) return -1;
return ans;
}
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... |