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 "dna.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MX_N = 1e5;
ll ps[3][3][MX_N]; // ATC
void init(std::string a, std::string b) {
ll n = a.size();
for(ll i=0;i<n;i++)
{
ll av,bv;
if(a[i]=='A') av=0;
else if(a[i]=='T') av=1;
else av=2;
if(b[i]=='A') bv=0;
else if(b[i]=='T') bv=1;
else bv=2;
ps[av][bv][i]++;
if(i)
{
for(ll j=0;j<3;j++)
{
for(ll k=0;k<3;k++)
{
ps[j][k][i]+=ps[j][k][i-1];
}
}
}
}
}
int get_distance(int x, int y) {
ll matrix[3][3];
for(ll i=0;i<3;i++)
{
for(ll j=0;j<3;j++)
{
matrix[i][j] = ps[i][j][y];
if(x)
matrix[i][j] -= ps[i][j][x-1];
}
}
ll cnt[2][3];
for(ll i=0;i<2;i++)
for(ll j=0;j<3;j++)
cnt[i][j]=0;
for(ll i=0;i<3;i++)
{
for(ll j=0;j<3;j++)
{
cnt[0][i] += matrix[i][j];
cnt[1][j] += matrix[i][j];
}
}
for(ll i=0;i<3;i++)
if(cnt[0][i]!=cnt[1][i])
return -1;
ll res[2] = {}; // swaping, permuting
for(ll i=0;i<3;i++)
{
for(ll j=i+1;j<3;j++)
{
ll mn = min(matrix[i][j],matrix[j][i]);
ll mx = max(matrix[i][j],matrix[j][i]);
res[0] += mn;
res[1] += mx-mn;
}
}
//cout<<res[0]<<" "<<res[1]<<"\n";
return res[0]+2*res[1]/3;
}
# | 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... |