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 <cmath>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
int cnt[N][3][3];
int f(char x) {
if (x == 'A') return 0;
if (x == 'C') return 1;
return 2;
}
void init(string a, string b) {
int n = (int)a.size();
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 2; j++) {
for (int k = 0; k <= 2; k++) {
cnt[i][j][k] = cnt[i - 1][j][k];
}
}
cnt[i][f(a[i - 1])][f(b[i - 1])]++;
}
}
int get_distance(int x, int y) {
++x; ++y;
int cntab = cnt[y][0][1] - cnt[x - 1][0][1], cntac = cnt[y][0][2] - cnt[x - 1][0][2],
cntba = cnt[y][1][0] - cnt[x - 1][1][0], cntbc = cnt[y][1][2] - cnt[x - 1][1][2],
cntca = cnt[y][2][0] - cnt[x - 1][2][0], cntcb = cnt[y][2][1] - cnt[x - 1][2][1];
if (cntab + cntac != cntba + cntca) return -1;
if (cntba + cntbc != cntab + cntcb) return -1;
if (cntca + cntcb != cntac + cntbc) return -1;
int ans = 0;
int u = min(cntab, cntba);
cntab -= u; cntba -= u;
ans += u;
u = min(cntac, cntca);
cntac -= u; cntca -= u;
ans += u;
u = min(cntbc, cntcb);
cntbc -= u; cntcb -= u;
ans += u;
int l = cntab + cntac + cntba + cntbc + cntca + cntcb;
l = 2 * l;
l /= 3;
ans += l;
return ans;
}
# | 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... |