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 <map>
#include <vector>
#include <bits/stdc++.h>
using ll = long long;
#define dbg(x) std::cerr << #x << " " << x << "\n"
const int MAX_N = 1e5;
int sum[MAX_N][3][3];
void init(std::string a, std::string b) {
std::map <char, int> mp;
mp['A'] = 0, mp['C'] = 1, mp['T'] = 2;
int n = a.size ();
for (int i = 0; i < n; i++) {
if (i > 0) {
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
sum[i][j][k] += sum[i - 1][j][k];
}
sum[i][mp[a[i]]][mp[b[i]]]++;
}
}
int cnt[3][3];
int get_distance(int x, int y) {
std::vector <int> freqA (3, 0), freqB (3, 0);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cnt[i][j] = sum[y][i][j];
if (x > 0) {
cnt[i][j] -= sum[x - 1][i][j];
}
// dbg (i); dbg (j); dbg (cnt[i][j]);
freqA[i] += cnt[i][j];
freqB[j] += cnt[i][j];
}
}
for (int i = 0; i < 3; i++)
if (freqA[i] != freqB[i])
return -1;
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
int sub = std::min (cnt[i][j], cnt[j][i]);
ans += sub;
cnt[i][j] -= sub;
cnt[j][i] -= sub;
}
}
int to_add = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i != j && cnt[i][j]) {
to_add = cnt[i][j];
}
}
}
ans += 2 * to_add;
return ans;
}
# | 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... |