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;
#define g(x) "[" << #x << ": " << (x) << "] "
// a[i][from][to];
const int maxn = 100005;
int a[maxn][3][3];
int get(char &c){
if(c == 'A'){
return 0;
} else if(c == 'T'){
return 1;
} else{
return 2;
}
assert(false);
}
void init(string s, string b) {
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a[0][i][j] = 0;
}
}
for(int i=0;i<s.size();i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
a[i][j][k] = a[i-1][j][k];
}
}
a[i][get(s[i])][get(b[i])]++;
}
}
int get_distance(int x, int y) {
vector<vector<int>> cur(3, vector<int>(3));
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cur[i][j] += a[y][i][j];
if(x != 0){
cur[i][j] -= a[x-1][i][j];
}
}
}
int two = 0;
for(int i=0;i<3;i++){
int out = 0;
int in = 0;
for(int j=0;j<3;j++){
if(j == i){
continue;
}
out += cur[i][j];
in += cur[j][i];
}
if(in != out){
return -1;
}
}
for(int i=0;i<3;i++){
for(int j=i+1;j<3;j++){
int mn = min(cur[i][j], cur[j][i]);
two += mn;
cur[i][j] -= mn;
cur[j][i] -= mn;
}
}
int clockwise = min({cur[0][1], cur[1][2], cur[2][0]});
int counterclockwise = min({cur[0][2], cur[2][1], cur[1][0]});
int c2 = max({cur[0][1], cur[1][2], cur[2][0]});
int cc2 = max({cur[0][2], cur[2][1], cur[1][0]});
if(min(clockwise, counterclockwise) != 0){
assert(false);
}
if(clockwise == 0){
swap(clockwise, counterclockwise);
swap(c2, cc2);
}
if(min(c2, cc2) != 0 or clockwise != c2){
return -1;
}
return two + 2 * clockwise;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0;i<s.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... |