# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
717154 | hcng | 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 <bits/stdc++.h>
using namespace std;
#define long long long
#define endl '\n'
typedef vector<long> vec;
long func(char c) {
if (c == 'A') return 0;
if (c == 'T') return 1;
if (c == 'C') return 2;
}
vector<vector<vec>> psum = vector<vector<vec>>(n + 1, vector<vec>(3, vec(3, 0)));
void init(string u, string v) {
for (long i = 0; i < n; i++) {
psum[i + 1].assign(psum[i].begin(), psum[i].end());
psum[i + 1][func(u[i])][func[v[i]]]++;
}
}
int get_distance(int l, int r) {
vector<vec> mat(3, vec(3));
for (long i = 0; i < 3; i++) {
for (long j = 0; j < 3; j++) {
mat[i][j] = psum[r][i][j] - psum[l - 1][i][j];
}
}
long sum1, sum2;
for (long i = 0; i < 3; i++) {
sum1 = 0;
for (long j = 0; j < 3; j++) {
sum1 += mat[i][j];
}
sum2 = 0;
for (long j = 0; j < 3; j++) {
sum2 += mat[j][i];
}
if (sum1 != sum2) {
break;
}
}
if (sum1 != sum2) {
cout << -1 << endl;
continue;
}
long ans = 0;
for (long i = 0; i < 3; i++) {
for (long j = 0; j < i; j++) {
long temp = min(mat[i][j], mat[j][i]);
mat[i][j] -= temp;
mat[j][i] -= temp;
ans += temp;
}
}
ans += mat[0][1] + mat[1][0];
return ans;
}