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>
#define ll long long int
using namespace std;
string aa, bb;
void init(std::string a, std::string b) {
aa = a, bb = b;
}
int get_distance(int x, int y) {
string a, b;
for (ll i = x; i <= y; i++) a += aa[i];
for (ll i = x; i <= y; i++) b += bb[i];
if (x == y) {
if (a != b) return -1;
return 0;
} else if (y - x == 1) {
string rev = a;
if (a == b) return 0;
reverse(rev.begin(), rev.end());
if (rev == b) return 1;
else return -1;
} else {
if (a == b) return 0;
else {
if (a[0] == b[0]) {
string rem1, rem2;
rem1 += a[1];
rem1 += a[2];
rem2 += b[1];
rem2 += b[2];
reverse(rem1.begin(), rem1.end());
if (rem1 == rem2) return 1;
else return -1;
} else if (a[1] == b[1]) {
string rem1, rem2;
rem1 += a[0];
rem1 += a[2];
rem2 += b[0];
rem2 += b[2];
reverse(rem1.begin(), rem1.end());
if (rem1 == rem2) return 1;
else return -1;
} else if (a[2] == b[2]) {
string rem1, rem2;
rem1 += a[0];
rem1 += a[1];
rem2 += b[0];
rem2 += b[1];
reverse(rem1.begin(), rem1.end());
if (rem1 == rem2) return 1;
else return -1;
} else {
vector<char> one, two;
for (char ch : a) one.push_back(ch);
for (char ch : b) two.push_back(ch);
sort(one.begin(), one.end());
sort(two.begin(), two.end());
if (one == two) return 2;
else return -1;
}
}
}
}
# | 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... |