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;
using ll = long long;
const int N = 100001;
vector<int> A0(N,0), A1(N,0);
vector<int> T0(N,0), T1(N,0);
vector<int> C0(N,0), C1(N,0);
vector<int> AC(N,0), CA(N,0), AT(N,0), TA(N,0), TC(N,0), CT(N,0);
string s, t;
void init(string a, string b) {
s = a;
t = b;
int sz = (int)a.size();
for (int i=0; i<sz; i++) {
A0[i+1] = A0[i];
T0[i+1] = T0[i];
C0[i+1] = C0[i];
if (s[i] == 'A') A0[i+1]++;
if (s[i] == 'T') T0[i+1]++;
if (s[i] == 'C') C0[i+1]++;
}
for (int i=0; i<sz; i++) {
A1[i+1] = A1[i];
T1[i+1] = T1[i];
C1[i+1] = C1[i];
if (t[i] == 'A') A1[i+1]++;
if (t[i] == 'T') T1[i+1]++;
if (t[i] == 'C') C1[i+1]++;
}
for (int i=0; i<sz; i++) {
AC[i+1] = AC[i];
CA[i+1] = CA[i];
AT[i+1] = AT[i];
TA[i+1] = TA[i];
CT[i+1] = CT[i];
TC[i+1] = CT[i];
if (s[i] == 'A' && t[i] == 'C') AC[i+1]++;
if (s[i] == 'C' && t[i] == 'A') CA[i+1]++;
if (s[i] == 'A' && t[i] == 'T') AT[i+1]++;
if (s[i] == 'T' && t[i] == 'A') TA[i+1]++;
if (s[i] == 'C' && t[i] == 'T') CT[i+1]++;
if (s[i] == 'T' && t[i] == 'C') TC[i+1]++;
}
}
int get_distance(int x, int y) {
int ans = 0;
y++;
if ((A0[y] - A0[x] != A1[y] - A1[x]) || (T0[y] - T0[x] != T1[y] - T1[x]) || (C0[y] - C0[x] != C1[y] - C1[x])) return -1;
int ac = AC[y] - AC[x], ca = CA[y] - CA[x];
int at = AT[y] - AT[x], ta = TA[y] - TA[x];
int ct = CT[y] - CT[x], tc = TC[y] - TC[x];
int a = min(ac,ca);
int b = min(at,ta);
int c = min(ct,tc);
ans = ans + a + b + c;
ac -= a;
ca -= a;
at -= b;
ta -= b;
ct -= c;
tc -= c;
int d = min(ac,min(ta,ct));
ans += (2*d);
ac -= d;
ta -= d;
ct -= d;
int e = min(ca,min(at,tc));
ans += (2*e);
ca -= e;
at -= e;
tc -= e;
int f = min(at,min(tc,ca));
ans += (2*f);
at -= f;
tc -= f;
ca -= f;
int g = min(ta,min(ct,ac));
ans += (2*g);
ta -= g;
ct -= g;
ac -= g;
if (ac == 0 && ca == 0 && ct == 0 && tc == 0 && at == 0 && ta == 0) {
return ans;
}
else {
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... |