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 <cstdio>
#include <cassert>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1e5+2;
vector<int> A(MAX), Ab(MAX), C(MAX), Cb(MAX), T(MAX), Tb(MAX), AC(MAX), CA(MAX), AT(MAX), TA(MAX), CT(MAX), TC(MAX);
void init(std::string a, std::string b) {
int n = a.size();
for(int i = 0; i < n; i++){
if(a[i] == 'A') A[i+1]++;
if(a[i] == 'C') C[i+1]++;
if(a[i] == 'T') T[i+1]++;
if(b[i] == 'A') Ab[i+1]++;
if(b[i] == 'C') Cb[i+1]++;
if(b[i] == 'T') Tb[i+1]++;
if(a[i] == 'A'){
if(b[i] == 'C') AC[i+1]++;
if(b[i] == 'T') AT[i+1]++;
}
if(a[i] == 'C'){
if(b[i] == 'A') CA[i+1]++;
if(b[i] == 'T') CT[i+1]++;
}
if(a[i] == 'T'){
if(b[i] == 'A') TA[i+1]++;
if(b[i] == 'C') TC[i+1]++;
}
A[i+2] = A[i+1];
C[i+2] = C[i+1];
T[i+2] = T[i+1];
Ab[i+2] = Ab[i+1];
Cb[i+2] = Cb[i+1];
Tb[i+2] = Tb[i+1];
AC[i+2] = AC[i+1];
CA[i+2] = CA[i+1];
AT[i+2] = AT[i+1];
TA[i+2] = TA[i+1];
CT[i+2] = CT[i+1];
TC[i+2] = TC[i+1];
}
}
int get_distance(int x, int y) {
x++,y++;
if(A[y]-A[x-1] != Ab[y]-Ab[x-1]) return -1;
if(C[y]-C[x-1] != Cb[y]-Cb[x-1]) return -1;
if(T[y]-T[x-1] != Tb[y]-Tb[x-1]) return -1;
int a = AC[y]-AC[x-1], b = CA[y]-CA[x-1], c = AT[y]-AT[x-1], d = TA[y]-TA[x-1], e = CT[y]-CT[x-1], f = TC[y]-TC[x-1];
if(a > b) swap(a,b);
return (a+min(c,d)+min(e,f)+(2*b)-2*a);
}
# | 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... |