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<bits/stdc++.h>
#include "dna.h"
using namespace std;
vector<tuple<int, int, int>> prefix1;
vector<tuple<int, int, int>> prefix2;
vector<int> prefix;
int n;
void init(string a, string b) {
n = a.size();
prefix.resize(n);
prefix1.resize(n);
prefix2.resize(n);
for(int i = 0; i < n; i++){
if(i == 0){
prefix1[i] = {0, 0, 0};
prefix2[i] = {0, 0, 0};
if(a[i] == 'A'){
get<0> (prefix1[i])++;
}else if(a[i] == 'T'){
get<1>(prefix1[i])++;
}else get<2> (prefix1[i])++;
if(b[i] == 'A'){
get<0> (prefix2[i])++;
}else if(b[i] == 'T'){
get<1>(prefix2[i])++;
}else get<2> (prefix2[i])++;
}else{
prefix1[i] = prefix1[i - 1];
prefix2[i] = prefix2[i - 1];
if(a[i] == 'A'){
get<0> (prefix1[i])++;
}else if(a[i] == 'T'){
get<1>(prefix1[i])++;
}else get<2> (prefix1[i])++;
if(b[i] == 'A'){
get<0> (prefix2[i])++;
}else if(b[i] == 'T'){
get<1>(prefix2[i])++;
}else get<2> (prefix2[i])++;
}
if(a[i] != b[i]){
if(i == 0) prefix[i] = 1;
else prefix[i] = prefix[i-1] + 1;
}else{
if(i == 0) prefix[i] = 0;
else prefix[i] = prefix[i-1];
}
}
}
int get_distance(int x, int y) {
int da, db;
if(x > 0) da = get<0> (prefix1[y]) - get<0> (prefix1[x-1]);
else da = get<0> (prefix1[y]);
if(x > 0) db = get<0> (prefix2[y]) - get<0> (prefix2[x-1]);
else db = get<0> (prefix2[y]);
if(da != db) return -1;
if(x > 0) da = get<1> (prefix1[y]) - get<1> (prefix1[x-1]);
else da = get<1> (prefix1[y]);
if(x > 0) db = get<1> (prefix2[y]) - get<1> (prefix2[x-1]);
else db = get<1> (prefix2[y]);
if(da != db) return -1;
if(x > 0) da = get<2> (prefix1[y]) - get<2> (prefix1[x-1]);
else da = get<2> (prefix1[y]);
if(x > 0) db = get<2> (prefix2[y]) - get<2> (prefix2[x-1]);
else db = get<2> (prefix2[y]);
if(da != db) return -1;
int d;
if(x > 0) d = prefix[y] - prefix[x-1];
else d = prefix[y];
if(d % 2 != 0) return d / 2 + 1;
else return d / 2;
}
# | 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... |