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 char ch[] = {'A', 'T', 'C'};
int n, m, k;
string ADN[6];
vector<vector<int>> prefix;
vector<vector<int>> sumA, sumB;
void init(string a, string b) {
n = a.size();
m = 6; k = 3;
ADN[0] = "AT";
ADN[1] = "AC";
ADN[2] = "TC";
ADN[3] = "CT";
ADN[4] = "CA";
ADN[5] = "TA";
prefix.resize(n, vector<int> (m, 0));
sumA.resize(n, vector<int> (k, 0));
sumB.resize(n, vector<int> (k, 0));
for(int i = 0; i < n; i ++) {
string s = "";
s.push_back(a[i]);
s.push_back(b[i]);
for(int j = 0; j < m; j ++) {
prefix[i][j] = (i > 0 ? prefix[i - 1][j] : 0) + (s == ADN[j]);
}
}
for(int i = 0; i < n; i ++) {
for(int j = 0; j < k; j ++) {
sumA[i][j] = (i > 0 ? sumA[i - 1][j] : 0) + (a[i] == ch[j]);
sumB[i][j] = (i > 0 ? sumB[i - 1][j] : 0) + (b[i] == ch[j]);
}
}
}
int get_distance(int x, int y) {
for(int i = 0; i < k; i ++) {
int sA = sumA[y][i] - (x > 0 ? sumA[x - 1][i] : 0);
int sB = sumB[y][i] - (x > 0 ? sumB[x - 1][i] : 0);
if(sA != sB) return -1;
}
vector<int> dp(m, 0);
auto get = [&](int l, int r, int i) {
return prefix[r][i] - (l > 0 ? prefix[l - 1][i] : 0);
};
for(int i = 0; i < m; i ++) dp[i] = get(x, y, i);
int total = 0;
for(int i = 0; i < m; i ++) {
int j = m - 1 - i;
int v = min(dp[i], dp[j]);
dp[i] -= v;
dp[j] -= v;
total += v;
}
for(int i = 0; i < m; i ++) {
if(dp[i] == 0) continue ;
for(int j = 0; j < m; j ++) {
if(dp[j] == 0) continue ;
if(ADN[i][1] == ADN[j][0]) {
total += dp[i] * 2;
return total;
}
}
}
return total;
}
# | 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... |