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 = 2e5 + 3e2;
int pref[MAXN][6];
long long cnt[MAXN][2];
vector<vector<char>> dna = {{'A', 'C'}, {'C', 'A'}, {'A', 'T'}, {'T', 'A'}, {'T', 'C'}, {'C', 'T'}};
long long f(char ch){
if (ch == 'A') return 1ll;
if (ch == 'C') return 200000ll;
if (ch == 'T') return 40000000000ll;
return -1;
}
void init(string a, string b) {
int n = a.size();
for (int i = 1; i <= n; i++){
cnt[i][0] = cnt[i - 1][0] + f(a[i - 1]);
cnt[i][1] = cnt[i - 1][1] + f(b[i - 1]);
}
for (int i = 1; i <= n; i++){
for (int j = 0; j < 6; j++){
pref[i][j] = pref[i - 1][j] + (a[i - 1] == dna[j][0] && b[i - 1] == dna[j][1]);
}
}
}
int get_distance(int x, int y) {
x++, y++;
if (cnt[y][0] - cnt[x - 1][0] != cnt[y][1] - cnt[x - 1][1]) return -1;
int ans1 = 0, ans2 = 0;
for (int j = 0; j < 6; j += 2){
int a = pref[y][j] - pref[x - 1][j];
int b = pref[y][j + 1] - pref[x - 1][j + 1];
int c = min(a, b);
ans1 += c;
ans2 += a - c + b - c;
}
int res = ans1 + ans2 / 3 * 2;
return res;
}
# | 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... |