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;
int n;
int g[3][3][100000];
void init(std::string a, std::string b) {
n=a.size();
for(int i=0;i<3;i++){
for(int w=0;w<3;w++){
g[i][w][0]=0;
}
}
for(int i=0;i<n;i++){
if(i){
for(int w=0;w<3;w++){
for(int j=0;j<3;j++){
g[j][w][i]=g[j][w][i-1];
}
}
}
if(a[i]!=b[i])g[(a[i]=='A'?0:1+(a[i]=='T'))][(b[i]=='A'?0:1+(b[i]=='T'))][i]++;
}
}
int get_distance(int l, int r) {
int ans=0;
int a[3][3];
int x[3]={0,0,0},y[3]={0,0,0};
for(int w=0;w<3;w++){
for(int j=0;j<3;j++){
a[w][j]=g[w][j][r]-(l?g[w][j][l-1]:0);
x[w]+=a[w][j];
y[j]+=a[w][j];
}
}
// cout<<x[0]<<' '<<y[0]<<endl;
if(x[0]!=y[0]||x[1]!=y[1]||x[2]!=y[2])return -1;
for(int i=0;i<3;i++){
for(int w=0;w<3;w++){
int k=min(a[i][w],a[w][i]);
ans+=k;
a[i][w]-=k;
a[w][i]-=k;
}
}
int g=0;
for(int i=0;i<3;i++){
for(int w=i+1;w<3;w++){
g+=a[i][w];
g+=a[w][i];
}
}
return ans+(g/3)*2;
}
# | 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... |