# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1141902 | redacode | DNA 돌연변이 (IOI21_dna) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
string a, b;
cin >> n >> q;
cin >> a;
cin >> b;
while(q--){
int x, y;
cin >> x >> y;
string ax="";
string bx="";
int freq1[3]={0,0,0};
int freq2[3]={0,0,0};
for(int i=x;i<=y;i++){
ax+=a[i];
if(a[i]=='A')freq1[0]++;
if(a[i]=='B')freq1[1]++;
if(a[i]=='C')freq1[2]++;
bx+=b[i];
if(b[i]=='A')freq2[0]++;
if(b[i]=='B')freq2[1]++;
if(b[i]=='C')freq2[2]++;
}
if(freq1[0]!=freq2[0] or freq1[1]!=freq2[1] or freq1[2]!=freq2[2]){
cout << -1 << endl;
}else if(x-y==2){
//cout << ax << " " << bx;
if(ax==bx){
cout << 0 << endl;
}else if((ax[0]==bx[1] and ax[1]==bx[0]) or (ax[2]==bx[1] and ax[1]==bx[2])){
cout << 1 << endl;
}else{
cout << 2 << endl;
}
}else{
if(ax==bx){
cout << 0 << endl;
}else{
cout << 1 << endl;
}
}
}
}