#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define rep(i, l, n) for (int i = l; i < (n); ++i)
#define sz(x) (int)x.size()
const char nl = '\n';
const int mod = 1e9+7;
const int NMAX = 1e5+10;
const int inf = 1e9+10;
int p0[2][NMAX], p1[2][NMAX], p2[2][NMAX];
int N, res[NMAX];
int pr[6][NMAX];
string s, t;
vector<char> X = {'A','C','T'};
vector<char> Y = {'A','C','T'};
void init(string a, string b) {
N = sz(a); s = a, t = b;
rep(i, 0, 2)
rep(j, 0, N) {
p0[i][j] = p1[i][j] = p2[i][j] = 0;
if (i == 0) {
if (a[j] == 'A')p0[0][j] += 1;
if (a[j] == 'C')p1[0][j] += 1;
if (a[j] == 'T')p2[0][j] += 1;
} else {
if (b[j] == 'A')p0[1][j] += 1;
if (b[j] == 'C')p1[1][j] += 1;
if (b[j] == 'T')p2[1][j] += 1;
}
if (j) {
p0[i][j] += p0[i][j-1];
p1[i][j] += p1[i][j-1];
p2[i][j] += p2[i][j-1];
}
}
rep(i, 0, N) {
if (a[i] != b[i])res[i] = 1;
if (i)res[i] += res[i-1];
}
int id = 0;
rep(i, 0, 3)
rep(j, 0, 3) {
if (X[i] == Y[j])continue;
rep(k, 0, N) {
if (a[k] == X[i] && b[k] == Y[j])pr[id][k] += 1;
if (k)pr[id][k] += pr[id][k-1];
}
id++;
}
}
int get_distance(int x, int y) {
bool ok = true;
//rep(i, 0, 3) {
int a = p0[0][y]-(x?p0[0][x-1]:0);
int b = p0[1][y]-(x?p0[1][x-1]:0);
ok &= (b==a);
//}
a = p1[0][y]-(x?p1[0][x-1]:0);
b = p1[1][y]-(x?p1[1][x-1]:0);
ok &= (b==a);
a = p2[0][y]-(x?p2[0][x-1]:0);
b = p2[1][y]-(x?p2[1][x-1]:0);
ok &= (b==a);
if (!ok)return -1;
int ans = 0;
map<pair<char, char>, int> mp;
int id = 0;
rep(i, 0, 3)
rep(j, 0, 3) {
if (X[i] == Y[j])continue;
mp[{X[i], Y[j]}] = pr[id][y]-(x?pr[id][x-1]:0);
id += 1;
}
vector<int> z;
rep(i, 0, 3)
rep(j, 0, 3) {
if (mp[{X[i], Y[j]}] == 0)continue;
a = mp[{X[i], Y[j]}], b = mp[{Y[j], X[i]}];
ans += min(a, b);
z.push_back(max(a, b)-min(a,b));
mp[{X[i], Y[j]}] = mp[{Y[j], X[i]}] = 0;
}
rep(i, 0, sz(z)-1)ans += z[i];
//int last = x-1;
//int ans = 0;
//rep(i, x, y+1) {
//if (last == -1) {
//if (p0[0][i] == p0[1][i] && p1[0][i] == p1[1][i] && p2[0][i] == p2[1][i]) {
//ans += (res[i]+1)/2;
//last = i;
//}
//} else {
//if (p0[0][i]-p0[0][last] == p0[1][i]-p0[1][last] &&
//p1[0][i]-p1[0][last] == p1[1][i]-p1[1][last] &&
//p2[0][i]-p2[0][last] == p2[1][i]-p2[1][last]) {
//ans += (res[i]-res[last]+1)/2;
//last = i;
//}
//}
//}
return ans;
//return (res[y]-(x?res[x-1]:0)+1)/2;
}
| # | 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... |