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;
constexpr int MAXN = 1e5 + 7;
int type[MAXN][7]; // ac at ca ct ta tc
int num[MAXN][3][2];
void init(string a, string b) {
for (int i = 0; i < a.size(); i++)
{
num[i + 1][(a[i] == 'A' ? 0 : (a[i] == 'C' ? 1 : 2))][0]++;
num[i + 1][(b[i] == 'A' ? 0 : (b[i] == 'C' ? 1 : 2))][1]++;
int curr = 6;
if (a[i] == 'A' && b[i] == 'C')
curr = 0;
else if (a[i] == 'A' && b[i] == 'T')
curr = 1;
else if (a[i] == 'C' && b[i] == 'A')
curr = 2;
else if (a[i] == 'C' && b[i] == 'T')
curr = 3;
else if (a[i] == 'T' && b[i] == 'A')
curr = 4;
else if (a[i] == 'T' && b[i] == 'C')
curr = 5;
type[i + 1][curr]++;
for (int h = 0; h < 6; h++){
type[i + 1][h] += type[i][h];
num[i + 1][h/2][h%2] += num[i][h/2][h%2];
}
}
}
int get_distance(int x, int y) {
y++;
if (num[y][0][0] - num[x][0][0] != num[y][0][1] - num[x][0][1] ||
num[y][1][0] - num[x][1][0] != num[y][1][1] - num[x][1][1] ||
num[y][2][0] - num[x][2][0] != num[y][2][1] - num[x][2][1])
return -1;
int curr = 0;
int res = 0;
curr += max(type[y][0] - type[x][0], type[y][2] - type[x][2]) - min(type[y][0] - type[x][0], type[y][2] - type[x][2]);
res += min(type[y][0] - type[x][0], type[y][2] - type[x][2]);
curr += max(type[y][1] - type[x][1], type[y][4] - type[x][4]) - min(type[y][1] - type[x][1], type[y][4] - type[x][4]);
res += min(type[y][1] - type[x][1], type[y][4] - type[x][4]);
curr += max(type[y][3] - type[x][3], type[y][5] - type[x][5]) - min(type[y][3] - type[x][3], type[y][5] - type[x][5]);
res += min(type[y][3] - type[x][3], type[y][5] - type[x][5]);
res += (curr / 3) * 2;
return res;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | 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... |