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 "dna.h"
#include<bits/stdc++.h>
using namespace std;
string s,s2;
void init(std::string a, std::string b) {
s = a;
s2 = b;
}
bool ispossible(string s1, string s2)
{
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
if (s1 == s2)
return 1;
return 0;
}
int CountSteps(string s1, string s2, int size)
{
int i = 0, j = 0;
int result = 0;
while (i < size) {
j = i;
while (s1[j] != s2[i]) {
j += 1;
}
while (i < j) {
char temp = s1[j];
s1[j] = s1[j - 1];
s1[j - 1] = temp;
j -= 1;
result += 1;
}
i += 1;
}
return result;
}
int get_distance(int x, int y) {
string temp,temp2;
for(int i=x;i<=y;i++)
{
temp+=s[i];
temp2+=s2[i];
}
if(!ispossible(temp,temp2))
return -1;
int res = CountSteps(temp,temp2,temp.size());
return res;
}
# | 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... |