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
*/
Compilation message (stderr)
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < one.size();i++){
| ~~^~~~~~~~~~~~
dna.cpp:34:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int x = i + 1; x < a.size();x++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |