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;
using ll = long long;
string A, B;
void init(std::string a, std::string b) {
A = a;
B = b;
}
int get_distance(int x, int y) {
string a = A.substr(x, y - x + 1);
string b = B.substr(x, y - x + 1);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a != b)
return -1;
if (y - x + 1 == 1)
return 0;
a = A.substr(x, y - x + 1);
b = B.substr(x, y - x + 1);
if (a == b)
return 0;
if (y - x + 1 == 2)
return 1;
ll ans = 0;
while (a != b) {
for (int i = 0; i < 3; i++) {
if (a[i] == b[i])
continue;
for (int j = 0; j < 3; j++) {
if (i == j)
continue;
if (b[j] == a[i]) {
ans += abs(i - j);
swap(b[i], b[j]);
}
}
}
}
return ans;
}
# | 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... |