이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "dna.h"
int n;
vector < array < int, 6 > > bit;
int
toi (char x, char y)
{
if (y > x) --y;
return (x - 'A') * 2 + y - 'A';
}
auto
bs (int i, int x)
{
int ans = 0;
while (x > 0)
{
ans += bit[x][i];
x -= (x + 1) & -(x + 1);
}
return ans;
}
auto
brs (int i, int l, int r)
{
int ans = bs (i, r);
if (l) ans -= bs (i, l - 1);
return ans;
}
void init(std::string a, std::string b) {
n = a.size ();
bit.resize (n);
for (int i = 0; i < n; ++i)
{
if (a[i] == 'T') a[i] = 'B';
if (b[i] == 'T') b[i] = 'B';
if (a[i] != b[i])
bit[i][toi (a[i], b[i])]++;
for (int j = 0; j < 6; ++j)
bit[i][j] += brs (j, i - ((i + 1) & -(i + 1)) + 1, i - 1);
}
}
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;
for (int k = 0; k < 10; ++k)
for (char x = 'A'; x <= 'C'; ++x)
for (char y = x + 1; y <= 'C'; ++y)
{
int m = min (a[toi (x, y)], a[toi (y, x)]);
c += m;
a[toi (x, y)] -= m;
a[toi (y, x)] -= m;
char z = 'A' + 'B' + 'C' - x - y;
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;
}
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... |