# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1001665 | vjudge1 | DNA 돌연변이 (IOI21_dna) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pf push_front
#define pi pair<int,int>
string a,b;
const int MAX = 1e5+1;
int n;
ll how[2][MAX][3];
map<char,int>mtch;
void init(string A, string B){
a = A;
b = B;
mtch['A']=0;
mtch['C']=1;
mtch['T']=2;
for(int i = 0; i <a.size(); i++){
for(int j = 0; j<3; j++){
how[0][i+1][j] = how[0][i][j] ;
how[1][i+1][j] = how[1][i][j] ;
}
// cout << mtch[A[i]]<<" s "<< mtch[B[i]]<<endl;
how[0][i+1][mtch[A[i]]]++;
how[1][i+1][mtch[B[i]]]++;
}
}
int get_distance(int x, int y){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll add = 0;
ll sub = 0;
ll mp[3];
memset(mp,0,sizeof(mp));
int vala,valb;
for(int i =0; i < 3; i++){
vala = how[0][y+1][i]-how[0][x][i];
valb = how[1][y+1][i]-how[1][x][i];
if(vala!=valb) return -1;
}
for(int i = x; i<= y; i++){
if(a[i]!=b[i]){
add++;
// cout << a[i]<< " " << mtch[a[i]]<<endl;
if(mp[mtch[a[i]]]){
sub++;
mp[mtch[a[i]]]--;
}
else mp[mtch[b[i]]]++;
}
}
//cout << add<<" "<<sub<< " "<< endl;
return add-sub;
}
int main(){
int 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)<<endl;
}
}