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 <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include "dna.h"
using namespace std;
const int maxn = 1e5 + 5;
int a_pref_sum[maxn][4];
int b_pref_sum[maxn][4];
int pref_sum[maxn];
string a, b;
vector<int> a_id[4], b_id[4];
int n;
void init(string _a, string _b) {
memset(a_pref_sum, 0, sizeof a_pref_sum);
memset(b_pref_sum, 0, sizeof b_pref_sum);
a = _a;
b = _b;
n = (int) a.size();
for(int i = 0; i < n; i++) {
if(a[i] == 'C') a[i] = 'B';
if(b[i] == 'C') b[i] = 'B';
}
for(int i = 0; i < n; i++) {
if(a[i] == 'T') a[i] = 'C';
if(b[i] == 'T') b[i] = 'C';
}
int cnt_a[3] = {0, 0, 0};
int cnt_b[3] = {0, 0, 0};
int sum = 0;
for(int i = 0; i < n; i++) {
int id_a = (int) (a[i] - 'A');
int id_b = (int) (b[i] - 'A');
cnt_a[id_a]++;
cnt_b[id_b]++;
for(int j = 0; j < 3; j++) {
a_pref_sum[i][j] = cnt_a[j];
b_pref_sum[i][j] = cnt_b[j];
}
if(a[i] != b[i]) {
sum++;
}
pref_sum[i] = sum;
}
}
int a_query(int &x, int &y, char c) {
if(x == 0) {
return a_pref_sum[y][c - 'A'];
}
return a_pref_sum[y][c - 'A'] - a_pref_sum[x - 1][c - 'A'];
}
int b_query(int &x, int &y, char c) {
if(x == 0) {
return b_pref_sum[y][c - 'A'];
}
return b_pref_sum[y][c - 'A'] - b_pref_sum[x - 1][c - 'A'];
}
int get_distance(int x, int y) {
if(a_query(x, y, 'A') == b_query(x, y, 'A') and a_query(x, y, 'B') == b_query(x, y, 'B') and a_query(x, y, 'C') == b_query(x, y, 'C')) {
if(a_query(x, y, 'C') > 0) {
if(x == 0) {
return pref_sum[y] / 2;
}
return (pref_sum[y] - pref_sum[x - 1]) / 2;
}
if(x == 0) {
return (pref_sum[y] + 1) / 2;
}
return (pref_sum[y] - pref_sum[x - 1] + 1) / 2;
}
return -1;
}
# | 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... |