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;
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
const int MAXN = 1e6 + 10;
int n, ps[MAXN], c1[MAXN], c2[MAXN], f[MAXN][3][3];
inline int r(char x) {
if (x == 'A') return 0;
if (x == 'T') return 1;
return 2;
}
void init(string a, string b) {
n = a.size();
a = '#' + a;
b = '#' + b;
for (int i = 1; i <= n; i++) {
ps[i] = ps[i - 1] + (a[i] != b[i]);
c1[i] = c1[i - 1] + (a[i] == 'A') - (b[i] == 'A');
c2[i] = c2[i - 1] + (a[i] == 'T') - (b[i] == 'T');
for (int a = 0; a < 3; a++)
for (int b = 0; b < 3; b++)
f[i][a][b] = f[i - 1][a][b];
f[i][r(a[i])][r(b[i])]++;
}
}
int get_distance(int x, int y) {
x++;
y++;
if (c1[y] - c1[x - 1] || c2[y] - c2[x - 1]) return -1;
int ans = 0;
int ms = ps[y] - ps[x - 1];
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
int c = min(f[y][i][j] - f[x - 1][i][j], f[y][j][i] - f[x - 1][j][i]);
ms -= 2 * c;
ans += c;
}
}
ans += ms * 2 / 3;
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... |