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;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const int N=1e5+5;
int sum[N][3][3];
int num(char c){
if(c=='A') return 0;
if(c=='T') return 1;
return 2;
}
void init(string a,string b){
for(int i=0;i<a.size();i++){
int x=num(a[i]),y=num(b[i]);
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
sum[i+1][j][k]=sum[i][j][k];
}
}
sum[i+1][x][y]++;
}
}
int get_distance(int x,int y){
int a[3][3],ans=0;
y++;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a[i][j]=sum[y][i][j]-sum[x][i][j];
}
}
for(int i=0;i<3;i++){
for(int j=i+1;j<3;j++){
int mn=min(a[i][j],a[j][i]);
ans+=mn;
a[i][j]-=mn;
a[j][i]-=mn;
}
}
if(min({a[0][1],a[1][2],a[2][0]})!=max({a[0][1],a[1][2],a[2][0]})){
return -1;
}
if(min({a[0][2],a[2][1],a[1][0]})!=max({a[0][2],a[2][1],a[1][0]})){
return -1;
}
ans+=min({a[0][1],a[1][2],a[2][0]})*2;
ans+=min({a[0][2],a[2][1],a[1][0]})*2;
return ans;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<a.size();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... |