# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
541836 | YassineBenYounes | 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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define pb push_back
#define ff first
#define ss second
string a, b;
int n, q;
int get_distance(int x, int y);
void init(string a, string b){
cin >> n >> q;
cin >> a >> b;
while(q--){
int x, y;cin >> x >> y;
cout << get_distance(x, y) << endl;
}
}
int get_distance(int x, int y){
string one = a.substr(x, y - x + 1);
string two = b.substr(x, y - x + 1);
int c = 0;
for(int i = 0; i < one.size();i++){
if(one[i] != two[i]){
int index = -1;
for(int x = i + 1; x < a.size();x++){
if(one[x] == two[i]){
index = x;break;
}
}
if(index == -1)return -1;
else{
swap(one[i], one[index]);
c++;
}
}
}
return c;
}
/*
5
1
ATACAT
ACTATA
1 3
*/
int main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
init(a, b);
}