# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
453801 | RGBB | Mutating DNA (IOI21_dna) | C++17 | 0 ms | 0 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 <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5;
int n,psa[MAXN][3][2],diff[MAXN][3][3],temp[3][3];
map<char,int>cmp;
int get_distance(int x,int y){
for(int i=0;i<3;i++){
int an=psa[y][i][0]-(x!=0?psa[x-1][i][0]:0);
int bn=psa[y][i][1]-(x!=0?psa[x-1][i][1]:0);
if(an!=bn)return -1;
}
int ret=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
temp[i][j]=diff[y][i][j]-(x!=0?diff[x-1][i][j]:0);
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(i==j)continue;
int m=min(temp[i][j],temp[j][i]);
ret+=m;
temp[i][j]-=m;
temp[j][i]-=m;
}
}
int s=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(i==j)continue;
s+=temp[i][j];
}
}
s*=2;
s/=3;
ret+=s;
return ret;
}
void init(string a,string b){
n=a.length();
cmp['A']=0;
cmp['T']=1;
cmp['C']=2;
for(int i=0;i<n;i++){
if(i!=0){
for(int j=0;j<3;j++){
for(int k=0;k<2;k++){
psa[i][j][k]=psa[i-1][j][k];
}
}
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
diff[i][j][k]=diff[i-1][j][k];
}
}
}
psa[i][cmp[a[i]]][0]++;
psa[i][cmp[b[i]]][1]++;
diff[i][cmp[a[i]]][cmp[b[i]]]++;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
init("ATCATCA","AATCATC");
cout<<get_distance(0,6)<<"\n";
}