제출 #880076

#제출 시각아이디문제언어결과실행 시간메모리
880076AkibAzmainMutating DNA (IOI21_dna)C++17
0 / 100
114 ms4628 KiB
#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 = '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;
            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;
            m = min (a[toi (z, y)], a[toi (y, z)]);
            c += m;
            a[toi (z, y)] -= m;
            a[toi (y, z)] -= m;
          }
  if (a[0] || a[1] || a[2] || a[3] || a[4] || a[5]) return -1;
  return c;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...