# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007521 | stdfloat | Mutating DNA (IOI21_dna) | C++17 | 55 ms | 23632 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>
#include "dna.h"
using namespace std;
vector<vector<vector<int>>> v;
void init(string a, string b) {
int n = (int)a.size();
for (int i = 0; i < n; i++) {
a[i] = (a[i] == 'A' ? '0' : (a[i] == 'T' ? '1' : '2'));
b[i] = (b[i] == 'A' ? '0' : (b[i] == 'T' ? '1' : '2'));
}
v.assign(n, vector<vector<int>>(3, vector<int>(3)));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) v[i][j][k] = (i ? v[i - 1][j][k] : 0) + (j == b[i] - '0' && k == a[i] - '0' && a[i] != b[i]);
}
}
}
int get_distance(int x, int y) {
vector<vector<int>> cnt(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) cnt[i][j] = v[y][i][j] - (x ? v[x - 1][i][j] : 0);
}
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int mn = min(cnt[i][j], cnt[j][i]);
ans += mn; cnt[i][j] -= mn; cnt[j][i] -= mn;
}
}
return (cnt[0][1] + cnt[0][2] == cnt[1][0] + cnt[1][2] && cnt[1][0] + cnt[1][2] == cnt[2][0] + cnt[2][1] ? ans + (cnt[0][1] + cnt[0][2] << 1) : -1);
}
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... |