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;
const int N = 100 * 1000 + 7;
int sum[2][3][N], ilz[3][3][N];
int Num(char z)
{
if(z == 'A')
return 0;
if(z == 'T')
return 1;
return 2;
}
int get_distance(int x, int y)
{
int w, i, j, p, k, d;
p = x + 1;
k = y + 1;
w = 0;
d = k - p + 1;
for(i = 0; i < 3; ++i)
if(sum[0][i][k] - sum[0][i][p - 1] != sum[1][i][k] - sum[1][i][p - 1])
return -1;
for(i = 0; i < 3; ++i)
{
for(j = 0; j <= i; ++j)
{
if(i == j)
{
d -= min(ilz[i][j][k] - ilz[i][j][p - 1], ilz[j][i][k] - ilz[j][i][p - 1]);
}
else
{
d -= 2 * min(ilz[i][j][k] - ilz[i][j][p - 1], ilz[j][i][k] - ilz[j][i][p - 1]);
w += min(ilz[i][j][k] - ilz[i][j][p - 1], ilz[j][i][k] - ilz[j][i][p - 1]);
}
}
}
return w + (d * 2 / 3);
}
void init(string a, string b)
{
int i, k, j, n1, n2;
for(i = 1; i <= (int)a.size(); ++i)
{
n1 = Num(a[i - 1]);
n2 = Num(b[i - 1]);
++sum[0][n1][i];
++sum[1][n2][i];
++ilz[n1][n2][i];
for(j = 0; j < 3; ++j)
{
sum[0][j][i] += sum[0][j][i - 1];
sum[1][j][i] += sum[1][j][i - 1];
}
for(j = 0; j < 3; ++j)
for(k = 0; k < 3; ++k)
ilz[j][k][i] += ilz[j][k][i - 1];
}
}
# | 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... |