# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
621424 | grubodupiec | 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 <cmath>
using namespace std;
const int MAXN = (10^5)+7;
int lista[MAXN][MAXN];
void init(string a, string b, int n, int lista1[MAXN][MAXN])
{
int c1=0;int c2=0;int c3=0;int c4=0;int c5=0;int c6=0;
for(int i=0;i<n;i++)
{
if(a[i]=='T'&&b[i]=='A') c1++;
if(a[i]=='A'&&b[i]=='T') c2++;
if(a[i]=='C'&&b[i]=='A') c3++;
if(a[i]=='A'&&b[i]=='C') c4++;
if(a[i]=='T'&&b[i]=='C') c5++;
if(a[i]=='C'&&b[i]=='T') c6++;
lista1[1][i]=c1;
lista1[2][i]=c2;
lista1[3][i]=c3;
lista1[4][i]=c4;
lista1[5][i]=c5;
lista1[6][i]=c6;
}
};
int get_distance(int x, int y,int lista[MAXN][MAXN])
{
int m=0;
int TA=lista[1][y]-lista[1][x-1];
int AT=lista[2][y]-lista[2][x-1];
int CA=lista[3][y]-lista[3][x-1];
int AC=lista[4][y]-lista[4][x-1];
int TC=lista[5][y]-lista[5][x-1];
int CT=lista[6][y]-lista[6][x-1];
int tat, cac, tct;
if (TA < AT) {
m += TA;
tat = AT - TA;
} else {
m += AT;
tat = TA - AT;
}
if (CA < AC) {
m += CA;
cac = AC - CA;
} else {
m += AC;
cac = CA - AC;
}
if (TC < CT) {
m += TC;
tct = CT - TC;
} else {
m += CT;
tct = TC - CT;
}
m+=2*tat;
if(!(tat==cac&&cac==tct)) return -1;
else return m;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0);
int n,h;
string f;
cin>>n>>h;
string a,b;
cin>>a>>b;
init(a,b,n,lista);
for(int i=0;i<h;i++)
{
int x;int y;
cin>>x>>y;
cout<<get_distance(x,y,lista)<<'\n';
}
return 0;
}