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;
#define pb push_back
string global_a, global_b;
void init(string a, string b){
global_a = a; global_b = b;
}
int get_distance(int x, int y){
int n = y-x+1;
string a, b;
for(int i=x; i<=y; i++){
a.pb(global_a[i]);
b.pb(global_b[i]);
}
string copy1 = a, copy2 = b;
sort(copy1.begin(), copy1.end());
sort(copy2.begin(), copy2.end());
if(copy1 != copy2) return -1;
int sum = 0;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(a[i] != b[i] && a[j] != b[j]){
swap(b[i], b[j]);
sum++;
}
}
}
return sum;
}
// int main(){
// init("ATACAT", "ACTATA");
// cout << get_distance(1, 3) << "\n";
// cout << get_distance(4, 5) << "\n";
// cout << get_distance(3, 5) << "\n";
// }
# | 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... |