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;
typedef long long ll;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define pb push_back
#define all(t) t.begin(), t.end()
int n = 0;
const int max_N = 1e5+5;
int A[max_N];
int B[max_N];
int S[max_N][3][3];
int V[max_N][2][3];
void init(string a, string b)
{
n = a.size();
rep(i,n)
{
if (a[i] == 'A')
A[i] = 0;
else if (a[i] == 'T')
A[i] = 1;
else
A[i] = 2;
}
rep(i,n)
{
if (b[i] == 'A')
B[i] = 0;
else if (b[i] == 'T')
B[i] = 1;
else
B[i] = 2;
}
rep(i,n)
{
if (i > 0) rep(j,3) rep(k,3) S[i][j][k] = S[i-1][j][k];
++S[i][A[i]][B[i]];
}
rep(i,n)
{
if (i > 0) rep(j,2) rep(k,3) V[i][j][k] = V[i-1][j][k];
++V[i][0][A[i]], ++V[i][1][B[i]];
}
}
inline int odl_S(int l, int p, int x1, int x2)
{
if (l == 0) return S[p][x1][x2];
return S[p][x1][x2] - S[l-1][x1][x2];
}
inline int odl_V(int l, int p, int idx, int val)
{
if (l == 0) return V[p][idx][val];
return V[p][idx][val] - V[l-1][idx][val];
}
int get_distance(int x, int y)
{
if (odl_V(x,y,0,0) != odl_V(x,y,1,0) or odl_V(x,y,0,1) != odl_V(x,y,1,1) or odl_V(x,y,0,2) != odl_V(x,y,1,2))
return -1;
int ile_zos = y - x + 1, wyn = 0;
rep(i,3) ile_zos -= odl_S(x,y,i,i);
if(ile_zos == 0)
return 0;
rep(i,3)
for (int j = i+1; j < 3; ++j)
wyn += min(odl_S(x,y,i,j),odl_S(x,y,j,i));
ile_zos -= 2*wyn;
if(ile_zos > 0)
wyn += ile_zos/3*2;
return wyn;
}
/*
int main()
{
init("ATACAT", "ACTATA");
cout << get_distance(1,3) << endl;
cout << get_distance(4,5) << endl;
cout << get_distance(3,5) << endl;
}
*/
# | 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... |