# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789342 | borisAngelov | Mutating DNA (IOI21_dna) | C++17 | 34 ms | 9756 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>
//#include "grader.cpp"
#include "dna.h"
using namespace std;
const int maxn = 100005;
int n;
int preffix1[maxn][3];
int preffix2[maxn][3];
int preffix_state[maxn][3][3];
int to_number[256];
void init(string a, string b)
{
n = a.size();
to_number['A'] = 0;
to_number['C'] = 1;
to_number['T'] = 2;
a = '#' + a;
b = '#' + b;
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j < 3; ++j)
{
preffix1[i][j] = preffix1[i - 1][j];
preffix2[i][j] = preffix2[i - 1][j];
}
++preffix1[i][to_number[a[i]]];
++preffix2[i][to_number[b[i]]];
for (int x = 0; x < 3; ++x)
{
for (int y = 0; y < 3; ++y)
{
preffix_state[i][x][y] = preffix_state[i - 1][x][y];
}
}
++preffix_state[i][to_number[a[i]]][to_number[b[i]]];
}
}
int curr_state[3][3];
int get_distance(int l, int r)
{
++l;
++r;
for (int i = 0; i < 3; ++i)
{
if (preffix1[r][i] - preffix1[l - 1][i] != preffix2[r][i] - preffix2[l - 1][i])
{
return -1;
}
}
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
curr_state[i][j] = preffix_state[r][i][j] - preffix_state[l - 1][i][j];
}
}
curr_state[0][0] = 0;
curr_state[1][1] = 0;
curr_state[2][2] = 0;
int ans = 0;
for (int i = 0; i < 3; ++i)
{
for (int j = i + 1; j < 3; ++j)
{
int swaps = min(curr_state[i][j], curr_state[j][i]);
ans += swaps;
curr_state[i][j] -= swaps;
curr_state[j][i] -= swaps;
}
}
int new_swaps = 0;
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
new_swaps += curr_state[i][j];
}
}
return ans + (new_swaps * 2) / 3;
}
/*
6 3
ATACAT
ACTATA
1 3
4 5
3 5
6 1
ATACAT
ACTATA
1 3
0 and 1 --> 0 1
0 and 2 --> 1 0
1 and 2 --> 0 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... |