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 N = 1e5 + 1;
int n, P[N][3][3];
int get (char c) {
switch(c) {
case 'A': return 0;
case 'C': return 1;
default: return 2;
}
}
void init(string a, string b) {
n = a.size();
for (int i = 1; i <= n; ++i) {
++P[i][get(a[i - 1])][get(b[i - 1])];
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
P[i][j][k] += P[i - 1][j][k];
}
}
}
}
int get_distance(int x, int y) {
++y;
int ans = 0;
int a[3][3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
a[i][j] = P[y][i][j] - P[x][i][j];
// cout << i << " " << j << " " << a[i][j] << endl;
}
}
// cout << "GOOOD" << endl;;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (i == j) {
continue;
}
int k = 3 - i - j;
int t = min(a[i][j], a[j][i]);
a[i][j] -= t;
a[j][i] -= t;
ans += t;
t = min(a[i][j], a[k][i]);
a[i][j] -= t;
a[k][i] -= t;
a[k][j] += t;
ans += t;
if (a[i][j]) {
return -1;
}
}
}
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... |