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;
vector<array<int,3>> p_a, p_b;
vector<int> diff;
int n;
// A,T,C
void init(string a, string b) {
n = a.size();
p_a.resize(n+1, {0,0,0});
p_b.resize(n+1,{0,0,0});
diff.resize(n+1,0);
for(int i = 0; i < n; i++) {
if(a[i]=='A') {
p_a[i+1] = {p_a[i][0] + 1, p_a[i][1], p_a[i][2]};
} else if(a[i] == 'T') {
p_a[i+1] = {p_a[i][0], p_a[i][1]+1, p_a[i][2]};
} else {
p_a[i+1] = {p_a[i][0], p_a[i][1], p_a[i][2]+1};
}
if(b[i]=='A') {
p_b[i+1] = {p_b[i][0] + 1, p_b[i][1], p_b[i][2]};
} else if(b[i] == 'T') {
p_b[i+1] = {p_b[i][0], p_b[i][1]+1, p_b[i][2]};
} else {
p_b[i+1] = {p_b[i][0], p_b[i][1], p_b[i][2]+1};
}
diff[i+1] = diff[i] + (!(a[i]==b[i]));
}
}
int get_distance(int x, int y) {
auto prx_a = p_a[x];
auto prx_b = p_b[x];
auto pry_a = p_a[y+1];
auto pry_b = p_b[y+1];
int d = diff[y+1] - diff[x];
if(pry_a[0] - prx_a[0] != pry_b[0] - prx_b[0]) {
return -1;
}
if(pry_a[1] - prx_a[1] != pry_b[1] - prx_b[1]) {
return -1;
}
if(pry_a[2] - prx_a[2] != pry_b[2] - prx_b[2]) {
return -1;
}
return d/2 + (d&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... |