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>
using namespace std;
#define ll long long
ll psum[100005][7];
// 1 at 2 ac 3 ta 4 tc 5 ca 6 ct
ll acnt[100005],tcnt[100005],ccnt[100005];
void init(std::string a, std::string b) {
for(int i=1;i<=6;i++){
psum[0][i]=0;
}
acnt[0]=tcnt[0]=ccnt[0]=0;
for(int i=0;i<a.length();i++){
acnt[i+1]=acnt[i],tcnt[i+1]=tcnt[i],ccnt[i+1]=ccnt[i];
acnt[i+1]+=(a[i]=='a');
acnt[i+1]-=(b[i]=='a');
tcnt[i+1]+=(a[i]=='t');
tcnt[i+1]-=(b[i]=='t');
ccnt[i+1]+=(a[i]=='c');
ccnt[i+1]-=(b[i]=='c');
}
for(int i=0;i<a.length();i++){
for(int j=1;j<=6;j++){
psum[i+1][j]=psum[i][j];
}
if(a[i]=='a'&&b[i]=='t'){
psum[i+1][1]++;
}
if(a[i]=='a'&&b[i]=='c'){
psum[i+1][2]++;
}
if(a[i]=='t'&&b[i]=='a'){
psum[i+1][3]++;
}
if(a[i]=='t'&&b[i]=='c'){
psum[i+1][4]++;
}
if(a[i]=='c'&&b[i]=='a'){
psum[i+1][5]++;
}
if(a[i]=='c'&&b[i]=='t'){
psum[i+1][6]++;
}
}
}
int get_distance(int x, int y) {
x++,y++;
if(acnt[y]-acnt[x-1]!=0 || tcnt[y]-tcnt[x-1]!=0 || ccnt[y]-ccnt[x-1]!=0){
return -1;
}
ll one=psum[y][1]-psum[x-1][1];
ll two=psum[y][2]-psum[x-1][2];
ll three=psum[y][3]-psum[x-1][3];
ll four=psum[y][4]-psum[x-1][4];
ll five=psum[y][5]-psum[x-1][5];
ll six=psum[y][6]-psum[x-1][6];
ll lol=min(one,three);
ll lol2=min(two,five);
ll lol3=min(four,six);
one-=lol,three-=lol;
return lol+lol2+lol3+max(one,three);
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:12:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<a.length();i++){
| ~^~~~~~~~~~~
dna.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<a.length();i++){
| ~^~~~~~~~~~~
# | 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... |