# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872607 | LucaLucaM | Mutating DNA (IOI21_dna) | C++17 | 32 ms | 7776 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 <iostream>
#include <algorithm>
std::string s, q;
int n;
const int NMAX = 1e5;
int sum[NMAX + 1][3][3];
void init(std::string a, std::string b) {
n = (int) a.size();
for (auto &ch : a) {
if (ch == 'A') {
ch = 0;
} else if (ch == 'C') {
ch = 1;
} else {
ch = 2;
}
}
for (auto &ch : b) {
if (ch == 'A') {
ch = 0;
} else if (ch == 'C') {
ch = 1;
} else {
ch = 2;
}
}
s = '$' + a, q = '$' + b;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
sum[i][j][k] = sum[i - 1][j][k];
}
}
sum[i][s[i]][q[i]]++;
}
}
int get_distance(int x, int y) {
++x, ++y;
int cnt[3][3] = {};
int delta[3] = {};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cnt[i][j] = sum[y][i][j] - sum[x - 1][i][j];
delta[i] += cnt[i][j];
delta[j] -= cnt[i][j];
}
}
if (delta[0] != 0 || delta[1] != 0 || delta[2] != 0) {
return -1;
}
std::vector<int> p = {0, 1, 2};
int answer = 0;
do {
int cur = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
cur += cnt[p[i]][p[j]];
}
}
answer = std::max(answer, cur);
} while (std::next_permutation(p.begin(), p.end()));
return answer;
}
/**
6 3
ATACAT
ACTATA
1 3
4 5
3 5
123
231
**/
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... |