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;
const int MAXN = 100000;
char achars[] = { 'A', 'A', 'T', 'T', 'C', 'C' };
char bchars[] = { 'T', 'C', 'A', 'C', 'A', 'T' };
int sums[MAXN+1][6];
void init(std::string a, std::string b) {
for (int i = 0; i < a.length(); ++i) {
for (int j = 0; j < 6; ++j) {
sums[i+1][j] = sums[i][j] + (a[i] == achars[j] && b[i] == bchars[j]);
}
}
}
inline int get(int x, int y, int idx) {
return sums[y+1][idx] - sums[x][idx];
}
inline void apply_pair(int& p1, int& p2, int& tot) {
int app = min(p1, p2);
p1 -= app;
p2 -= app;
tot += app;
//cout << "Paired " << app << endl;
}
inline void apply_triple(int& t1, int& t2, int& t3, int& tot) {
int app = min(min(t1, t2), t3);
t1 -= app;
t2 -= app;
t3 -= app;
tot += 2*app;
//cout << "Tripled " << app << endl;
}
int get_distance(int x, int y) {
int tot = 0;
int ab = get(x, y, 0);
int ac = get(x, y, 1);
int ba = get(x, y, 2);
int bc = get(x, y, 3);
int ca = get(x, y, 4);
int cb = get(x, y, 5);
apply_pair(ab, ba, tot);
apply_pair(ac, ca, tot);
apply_pair(bc, cb, tot);
apply_triple(ab, bc, ca, tot);
apply_triple(ba, ac, cb, tot);
if (ab == 0 && ac == 0 && ba == 0 && bc == 0 && ca == 0 && cb == 0) {
return tot;
} else {
return -1;
}
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:13:23: 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.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... |