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<vector>
int n,q;
std::string s;
std::string c;
std::vector<int> A;
std::vector<int> B;
std::vector<int> C;
std::vector<int> D;
std::vector<int> E;
std::vector<int> F;
std::vector<int> G;
std::vector<int> H;
std::vector<int> I;
std::vector<int> J;
std::vector<int> K;
std::vector<int> L;
std::vector<int> M;
void init(std::string a, std::string b) {
n=a.length();
s=a,c=b;
A.push_back(0),B.push_back(0),C.push_back(0),D.push_back(0),E.push_back(0),F.push_back(0),G.push_back(0);
H.push_back(0),I.push_back(0),J.push_back(0),K.push_back(0),L.push_back(0),M.push_back(0);
for(int i=0;i<n;i++){
if(a[i]!=b[i]){
A.push_back(1);
if(s[i]=='A'){
B.push_back(1);
C.push_back(0);
F.push_back(0);
}else if(s[i]=='C'){
C.push_back(1);
B.push_back(0);
F.push_back(0);
}else{
F.push_back(1);
B.push_back(0);
C.push_back(0);
}
if(c[i]=='A'){
D.push_back(1);
E.push_back(0);
G.push_back(0);
}else if(c[i]=='C'){
E.push_back(1);
D.push_back(0);
G.push_back(0);
}else{
G.push_back(1);
D.push_back(0);
E.push_back(0);
}
if(s[i]=='A' && c[i]=='T'){
H.push_back(1);
I.push_back(0);
J.push_back(0);
K.push_back(0);
L.push_back(0);
M.push_back(0);
}else if(s[i]=='A' && c[i]=='C'){
H.push_back(0);
I.push_back(1);
J.push_back(0);
K.push_back(0);
L.push_back(0);
M.push_back(0);
}else if(s[i]=='C' && c[i]=='T'){
H.push_back(0);
I.push_back(0);
J.push_back(1);
K.push_back(0);
L.push_back(0);
M.push_back(0);
}else if(s[i]=='T' && c[i]=='A'){
H.push_back(0);
I.push_back(0);
J.push_back(0);
K.push_back(1);
L.push_back(0);
M.push_back(0);
}else if(s[i]=='C' && c[i]=='A'){
H.push_back(0);
I.push_back(0);
J.push_back(0);
K.push_back(0);
L.push_back(1);
M.push_back(0);
}else{
H.push_back(0);
I.push_back(0);
J.push_back(0);
K.push_back(0);
L.push_back(0);
M.push_back(1);
}
}else{
A.push_back(0);
B.push_back(0);
C.push_back(0);
D.push_back(0);
E.push_back(0);
F.push_back(0);
G.push_back(0);
H.push_back(0);
I.push_back(0);
J.push_back(0);
K.push_back(0);
L.push_back(0);
M.push_back(0);
}
}
for(int i=1;i<=n;i++){
A[i]+=A[i-1];
B[i]+=B[i-1];
C[i]+=C[i-1];
D[i]+=D[i-1];
E[i]+=E[i-1];
F[i]+=F[i-1];
G[i]+=G[i-1];
H[i]+=H[i-1];
I[i]+=I[i-1];
J[i]+=J[i-1];
K[i]+=K[i-1];
L[i]+=L[i-1];
M[i]+=M[i-1];
}
while(q--){
int x,y;
get_distance(x,y);
}
}
int get_distance(int x, int y) {
int j=A[y+1]-A[x],h1=B[y+1]-B[x],h2=D[y+1]-D[x],l1=C[y+1]-C[x],l2=E[y+1]-E[x],k1=F[y+1]-F[x],k2=G[y+1]-G[x];
int f1=H[y+1]-H[x],f2=K[y+1]-K[x],v1=I[y+1]-I[x],v2=L[y+1]-L[x],b1=J[y+1]-J[x],b2=M[y+1]-M[x];
if((h1+l1+k1)==j && h1==h2 && l1==l2 && k1==k2){
int e=(f1+f2+v1+v2+b1+b2);
int r=abs(f1-f2);
e-=(3*r);
return ((2*r)+(e/2));
// if(j%3==1){
// return j/2;
// }else if(j%3==2){
// return (j/3)+1;
// }else{
// return 2*(j/3);
// }
}else{
return -1;
}
}
//7 3
//ATATATA
//TATTATT
//1 5
//0 2
//0 6
//3 2
//ATC
//CAT
//0 2
//0 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... |