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;
const int MAXN = 1e5+5;
int pre[MAXN][3][3];
int num[MAXN][3];
int n;
int nsum(int l, int r, int v) {
return num[r+1][v] - num[l][v];
}
int psum(int l, int r, int v1, int v2) {
return pre[r+1][v1][v2] - pre[l][v1][v2];
}
void init(string a, string b) {
n = a.size();
map<char, int> conv({{'A', 0}, {'C', 1}, {'T', 2}});
for (int i = 0; i < n; i++) {
int u = conv[a[i]];
int v = conv[b[i]];
pre[i+1][u][v] = 1;
num[i+1][u]++;
num[i+1][v]--;
for (int a = 0; a < 3; a++) {
for (int b = 0; b < 3; b++) pre[i+1][a][b] += pre[i][a][b];
num[i+1][a] += num[i][a];
}
}
}
int get_distance(int x, int y) {
for (int i = 0; i < 3; i++) if (nsum(x, y, i) != 0) return -1;
int s = 0;
for (int i = 0; i < 3; i++) {
int j = (i+1)%3;
int u = psum(x, y, i, j), v = psum(x, y, j, i);
s += min(u, v);
if (i == 0) s += 2*(max(u, v) - min(u, v));
}
return s;
}
# | 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... |