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 <vector>
#include <string>
using namespace std;
vector<int> mutationCount;
void init(string a, string b) {
int n = a.length();
mutationCount.resize(n, 0);
for (int i = 0; i < n; i++) {
mutationCount[i] = (a[i] != b[i]) ? 1 : 0;
if (i > 0) {
mutationCount[i] += mutationCount[i - 1];
}
}
}
int get_distance(int x, int y) {
int mutationInRange = mutationCount[y] - ((x > 0) ? mutationCount[x - 1] : 0);
int substringLength = y - x + 1;
int nonMutationCount = substringLength - mutationInRange;
if (mutationInRange == 0 || nonMutationCount == 0) {
return 0;
} else if (nonMutationCount % 2 == 0) {
return nonMutationCount / 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... |