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 <string>
#include <bits/stdc++.h>
using namespace std;
void init(std::string a, std::string b);
int get_distance(int x, int y);
int ps[6][100000];
void init(std::string a, std::string b) {
string patt[6] = {"CA", "AC", "TA", "AT", "CT", "TC"};
for(int i=0; i<a.size(); i++) {
for(int j=0; j<6; j++) {
string now;
now += a[i];
now += b[i];
ps[j][i] = (i==0 ? 0 : ps[j][i-1]) + (now == patt[j]);
}
}
}
int get_distance(int x, int y) {
int res[6];
for(int i=0; i<6; i++) res[i] = ps[i][y] - (x==0 ? 0 : ps[i][x-1]);
if(res[0] + res[4] != res[1] + res[5]) return -1;
if(res[1] + res[3] != res[0] + res[2]) return -1;
if(res[2] + res[5] != res[3] + res[4]) return -1;
int m1 = min(res[0], res[1]), m2 = min(res[2], res[3]), m3 = min(res[4], res[5]);
int ans = m1 + m2 + m3;
res[0] -= m1;
res[1] -= m1;
res[2] -= m2;
res[3] -= m2;
res[4] -= m3;
res[5] -= m3;
int sum = 0;
for(int i=0; i<6; i++) sum += res[i];
ans += max(0, sum - 1);
return ans;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | 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... |