# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466317 | popovicirobert | Mutating DNA (IOI21_dna) | C++17 | 53 ms | 7444 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 <bits/stdc++.h>
using namespace std;
constexpr int N = (int)1e5;
constexpr int SIGMA = 256;
static int freq[N + 1][3][3];
static int id[SIGMA];
static int n;
void init(std::string a, std::string b) {
id['A'] = 0;
id['C'] = 1;
id['T'] = 2;
n = a.size();
a = " " + a;
b = " " + b;
for (int i = 1; i <= n; i++) {
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
freq[i][x][y] = freq[i - 1][x][y] + (id[a[i]] == x && id[b[i]] == y);
}
}
}
}
int get_distance(int x, int y) {
x++, y++;
static int currFreq[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
currFreq[i][j] = freq[y][i][j] - freq[x - 1][i][j];
// cerr << currFreq[i][j] << " ";
}
// cerr << "\n";
}
// cerr << "\n";
int answer = 0;
auto Update = [&answer](int id1, int id2) {
int curr = min(currFreq[id1][id2], currFreq[id2][id1]);
currFreq[id1][id2] -= curr;
currFreq[id2][id1] -= curr;
answer += curr;
};
Update(0, 1);
Update(1, 2);
Update(0, 2);
if (currFreq[0][1] != currFreq[1][2] || currFreq[1][2] != currFreq[2][0] ||
currFreq[0][2] != currFreq[2][1] || currFreq[2][1] != currFreq[1][0]) {
return -1;
}
int mx = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i != j) {
mx = max(mx, currFreq[i][j]);
}
}
}
answer += 2 * mx;
// cerr << "DEBUG: " << mx << "\n";
return answer;
}
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... |