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 <bits/stdc++.h>
using namespace std;
#include "dna.h"
int n;
vector < array < int, 6 > > ps;
int
toi (char x, char y)
{
if (y > x) --y;
return (x - 'A') * 2 + y - 'A';
}
auto
brs (int i, int l, int r)
{
int ans = ps[r][i];
if (l) ans -= ps[l - 1][i];
return ans;
}
void init(std::string a, std::string b) {
n = a.size ();
ps.resize (n);
for (int i = 0; i < n; ++i)
{
if (a[i] == 'T') a[i] = 'B';
if (b[i] == 'T') b[i] = 'B';
if (i) ps[i] = ps[i - 1];
if (a[i] != b[i]) ps[i][toi (a[i], b[i])]++;
}
}
int get_distance(int x, int y) {
array < int, 6 > a = { brs (0, x, y), brs (1, x, y), brs (2, x, y),
brs (3, x, y), brs (4, x, y), brs (5, x, y) };
int c = 0;
auto fn = [&] ()
{
for (char x = 'A'; x <= 'C'; ++x)
for (char y = 'A'; y <= 'C'; ++y)
if (x != y)
{
int m = min (a[toi (x, y)], a[toi (y, x)]);
c += m;
a[toi (x, y)] -= m;
a[toi (y, x)] -= m;
}
};
fn ();
for (char x = 'A'; x <= 'C'; ++x)
for (char y = 'A'; y <= 'C'; ++y)
if (x != y)
{
char z = 'A' + 'B' + 'C' - x - y;
int m = min (a[toi (x, y)], a[toi (z, x)]);
c += m;
a[toi (x, y)] -= m;
a[toi (z, x)] -= m;
a[toi (z, y)] += m;
fn ();
}
if (a[0] || a[1] || a[2] || a[3] || a[4] || a[5]) return -1;
return c;
}
# | 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... |