# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1142537 | sam12345678910112 | Mutating DNA (IOI21_dna) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
# define ll long long
string A ,B;
int f[100003];
int fra[100003];
int frt[100003];
int fra2[100003];
int frt2[100003];
void init(string a, string b){
string A=a;
string B=b;
for(int so=0;so<A.size();so++){
f[so]=0;
if(so!=0){f[so]+=f[so];}
if(A[so]!=B[so]){ f[so]+=1;}
if(A[so]=='T'){frt[so]=0;frt[so]+=1+frt[max(so-1,0)];}
if(A[so]=='A'){fra[so]=0;fra[so]+=1+fra[max(so-1,0)];}
if(B[so]=='T'){frt2[so]=0;frt2[so]+=1+frt2[max(so-1,0)];}
if(B[so]=='A'){fra2[so]=0;fra2[so]+=1+fra2[max(so-1,0)];}
}
}
int get_distance(int x, int y){
if(frt[y]-frt[x]==frt2[y]-frt2[x]&&fra[y]-fra[x]==fra2[y]-fra2[x]){return f[y]-f[x];}
else{ return -1;}
}
int main() {
ll n,q;
cin>>n>>q;
string a,b;
cin>>a>>b;
init(a,b);
int x,y;
while(q--){
cin>>x>>y;
cout<<get_distance(x,y);
}
}