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;
long long n,q,x,y,ans,len,temp1,temp2,cnt[100100][5][5],freqa[5][100100],freqb[5][100100];
void init(std::string a, std::string b) {
for(int i=0;i<n;i++){
if(i>0){
freqa[1][i]=freqa[1][i-1];
freqb[1][i]=freqb[1][i-1];
freqa[2][i]=freqa[2][i-1];
freqb[2][i]=freqb[2][i-1];
freqa[3][i]=freqa[3][i-1];
freqb[3][i]=freqb[3][i-1];
}
if(a[i]=='A'){
freqa[1][i]++;
}else if(a[i]=='T'){
freqa[2][i]++;
}else{
freqa[3][i]++;
}
if(b[i]=='A'){
freqb[1][i]++;
}else if(b[i]=='T'){
freqb[2][i]++;
}else{
freqb[3][i]++;
}
for(int j=1;j<=3;j++){
for(int k=1;k<=3;k++){
if(i>0){
cnt[i][j][k]=cnt[i-1][j][k];
}
}
}
if(a[i]=='A'){
if(b[i]=='A'){
cnt[i][1][1]++;
}else if(b[i]=='T'){
cnt[i][1][2]++;
}else{
cnt[i][1][3]++;
}
}else if(a[i]=='T'){
if(b[i]=='A'){
cnt[i][2][1]++;
}else if(b[i]=='T'){
cnt[i][2][2]++;
}else{
cnt[i][2][3]++;
}
}else{
if(b[i]=='A'){
cnt[i][3][1]++;
}else if(b[i]=='T'){
cnt[i][3][2]++;
}else{
cnt[i][3][3]++;
}
}
}
}
int get_distance(int x, int y) {
ans=0;
temp1=0;
temp2=0;
if((freqa[1][y]-freqa[1][x-1]!=freqb[1][y]-freqb[1][x-1])||(freqa[2][y]-freqa[2][x-1]!=freqb[2][y]-freqb[2][x-1])||(freqa[3][y]-freqa[3][x-1]!=freqb[3][y]-freqb[3][x-1])){
return -1;
}
temp1=(cnt[y][1][2]-cnt[x-1][1][2])+(cnt[y][2][3]-cnt[x-1][2][3])+(cnt[y][3][1]-cnt[x-1][3][1]);
temp2=(cnt[y][1][3]-cnt[x-1][1][3])+(cnt[y][3][2]-cnt[x-1][3][2])+(cnt[y][2][1]-cnt[x-1][2][1]);
ans=abs(temp1-temp2)*2/3+min(temp1,temp2);
return ans;
}
# | 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... |