# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756546 | caganyanmaz | Mutating DNA (IOI21_dna) | C++17 | 55 ms | 6252 KiB |
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;
struct Fenwick
{
int n;
vector<int> data;
Fenwick(int n) : n(n), data(n + 1) {}
Fenwick() : Fenwick(0) {}
void update(int i, int val) { for (++i;i<data.size();i+=i&(-i)) data[i] += val; }
int get(int i) { int res=0; for (;i;i-=i&(-i)) res += data[i]; return res; }
int get(int l, int r) { return get(r) - get(l); }
};
Fenwick d[3][3];
int v[3][3];
int cc(char c)
{
switch (c)
{
case 'A':
return 0;
case 'T':
return 1;
case 'C':
return 2;
default:
assert(false);
}
}
void init(string a, string b)
{
int n = a.size();
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (i != j)
d[i][j] = Fenwick(n);
for (int i = 0; i < n; i++)
{
int x = cc(a[i]), y = cc(b[i]);
if (x != y)
d[x][y].update(i, 1);
}
}
bool check(int x)
{
int sum = 0;
for (int i = 0; i < 3; i++)
sum += v[i][x] - v[x][i];
return !sum;
}
int get_distance(int l, int r)
{
r++;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
v[i][j] = (i == j) ? 0 : d[i][j].get(l, r);
//for (int i = 0; i < 3; i++)
//{
// for (int j = 0; j < 3; j++)
// cout << v[i][j] << " ";
// cout << "\n";
//}
if (check(0) && check(1) && check(2))
{
return
min(v[0][1], v[1][0]) +
min(v[0][2], v[2][0]) +
min(v[1][2], v[2][1]) +
2 * (v[0][1] + v[1][0] - 2 * min(v[0][1], v[1][0]));
}
else
return -1;
}
Compilation message (stderr)
# | 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... |