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 <bits/stdc++.h>
#include <cstdio>
#include <cassert>
#include <string>
#include <vector>
using namespace std;
const int MX = 1e5+5;
int contA1[MX], contC1[MX], contT1[MX];
int contA2[MX], contC2[MX], contT2[MX];
int AC[MX], AT[MX], CA[MX], CT[MX], TA[MX], TC[MX];
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define F0R(i, b) FOR(i, 0, b)
#define sz(v) (int)(v).size()
void init(std::string a, std::string b) {
FOR(i, 1, sz(a)+1){
contA1[i] = contA1[i-1] + (a[i-1] == 'A');
contC1[i] = contC1[i-1] + (a[i-1] == 'C');
contT1[i] = contT1[i-1] + (a[i-1] == 'T');
}
FOR(i, 1, sz(b)+1){
contA2[i] = contA2[i-1] + (b[i-1] == 'A');
contC2[i] = contC2[i-1] + (b[i-1] == 'C');
contT2[i] = contT2[i-1] + (b[i-1] == 'T');
}
FOR(i, 1, sz(a)+1){
AC[i] = AC[i-1] + (a[i-1] == 'A' && b[i-1] == 'C');
AT[i] = AT[i-1] + (a[i-1] == 'A' && b[i-1] == 'T');
CA[i] = CA[i-1] + (a[i-1] == 'C' && b[i-1] == 'A');
CT[i] = CT[i-1] + (a[i-1] == 'C' && b[i-1] == 'T');
TA[i] = TA[i-1] + (a[i-1] == 'T' && b[i-1] == 'A');
TC[i] = TC[i-1] + (a[i-1] == 'T' && b[i-1] == 'C');
}
}
int get_distance(int x, int y) {
if(contA1[y+1] - contA1[x] != contA2[y+1] - contA2[x]) return -1;
if(contC1[y+1] - contC1[x] != contC2[y+1] - contC2[x]) return -1;
if(contT1[y+1] - contT1[x] != contT2[y+1] - contT2[x]) return -1;
int ret = 0;
int ac = AC[y+1] - AC[x], at = AT[y+1] - AT[x], ca = CA[y+1] - CA[x];
int ct = CT[y+1] - CT[x], ta = TA[y+1] - TA[x], tc = TC[y+1] - TC[x];
// cycles of size three
if(min({ac, ct, ta}) > 0){
ret += 3 * min({ac, ct, ta}) - 1;
ac -= min({ac, ct, ta});
ct -= min({ac, ct, ta});
ta -= min({ac, ct, ta});
}
if(min({at, tc, ca}) > 0){
ret += 3 * min({at, tc, ca}) - 1;
at -= min({at, tc, ca});
tc -= min({at, tc, ca});
ca -= min({at, tc, ca});
}
if(min(ac, ca) > 0){
ret += 2 * min(ac, ca) - 1;
}
if(min(at, ta) > 0){
ret += 2 * min(at, ta) - 1;
}
if(min(ct, tc) > 0){
ret += 2 * min(ct, tc) - 1;
}
return ret;
}
# | 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... |