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;
#define ll long long
#define ln '\n'
const int N = 1e5 + 5;
int same[N];
int n;
vector<int> wa[3], wb[3];
void init(std::string a, std::string b) {
n = a.size();
for (int i = 0; i < n; i++) same[i] = (a[i] == b[i]);
for (int i = 0; i < n; i++) same[i] += same[i-1];
for (int i = 0; i < n; i++){
if (a[i] == 'A') wa[0].push_back(i);
else if (a[i] == 'C') wa[1].push_back(i);
else wa[2].push_back(i);
}
for (int i = 0; i < n; i++){
if (b[i] == 'A') wb[0].push_back(i);
else if (b[i] == 'C') wb[1].push_back(i);
else wb[2].push_back(i);
}
}
int get_distance(int x, int y) {
bool ok = true;
for (int i = 0; i < 3; i++){
int c1 = upper_bound(wa[i].begin(), wa[i].end(), y) - lower_bound(wa[i].begin(), wa[i].end(), x);
int c2 = upper_bound(wb[i].begin(), wb[i].end(), y) - lower_bound(wb[i].begin(), wb[i].end(), x);
if (c1 != c2) {ok = false; break;}
}
if (!ok) return -1;
return y-x- (same[y] - ((x-1 < 0)? 0: same[x-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... |