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>
using namespace std;
#define MAX 100001
int apsum[MAX][2], tpsum[MAX][2], cpsum[MAX][2];
tuple<int, int, int, int, int, int> meow[MAX];
//AT, TA, AC, CA, TC, CT
void init(string a, string b){
int acarry1=0, tcarry1=0, ccarry1=0, acarry2=0, tcarry2=0, ccarry2=0;
int at=0, ta=0, ac=0, ca=0, tc=0, ct=0;
for (int x = 0; x < (int)a.size(); x++){
if (a[x] == 'A') acarry1++;
else if (a[x] == 'T') tcarry1++;
else if (a[x] == 'C') ccarry1++;
if (b[x] == 'A') acarry2++;
else if (b[x] == 'T') tcarry2++;
else if (b[x] == 'C') ccarry2++;
apsum[x][0] = acarry1;
tpsum[x][0] = tcarry1;
cpsum[x][0] = ccarry1;
apsum[x][1] = acarry2;
tpsum[x][1] = tcarry2;
cpsum[x][1] = ccarry2;
if (a[x] == 'A' && b[x] == 'T') at++;
else if (a[x] == 'T' && b[x] == 'A') ta++;
else if (a[x] == 'A' && b[x] == 'C') ac++;
else if (a[x] == 'C' && b[x] == 'A') ca++;
else if (a[x] == 'T' && b[x] == 'C') tc++;
else if (a[x] == 'C' && b[x] == 'T') ct++;
meow[x] = make_tuple(at, ta, ac, ca, tc, ct);
}
}
int get_distance(int x, int y){
int at=0, ta=0, ac=0, ca=0, tc=0, ct=0;
if (x != 0){
if (apsum[y][0]-apsum[x-1][0] != apsum[y][1]-apsum[x-1][1] ||
tpsum[y][0]-tpsum[x-1][0] != tpsum[y][1]-tpsum[x-1][1] ||
cpsum[y][0]-cpsum[x-1][0] != cpsum[y][1]-cpsum[x-1][1]
){
return -1;
}
at = get<0>(meow[y])-get<0>(meow[x-1]);
ta = get<1>(meow[y])-get<1>(meow[x-1]);
ac = get<2>(meow[y])-get<2>(meow[x-1]);
ca = get<3>(meow[y])-get<3>(meow[x-1]);
tc = get<4>(meow[y])-get<4>(meow[x-1]);
ct = get<5>(meow[y])-get<5>(meow[x-1]);
}
else{
if (apsum[y][0] != apsum[y][1] ||
tpsum[y][0] != tpsum[y][1] ||
cpsum[y][0] != cpsum[y][1]
){
return -1;
}
at = get<0>(meow[y]);
ta = get<1>(meow[y]);
ac = get<2>(meow[y]);
ca = get<3>(meow[y]);
tc = get<4>(meow[y]);
ct = get<5>(meow[y]);
}
//now it is guaranteed that we are able to somehow rearrange it
//we would always prefer to fix 2-cycles before hand? with one swap
//leaving only 3-cycles that can be fixed with 2 swaps?
int ans = 0;
int sweep = min(at, ta);
ans += sweep; at -= sweep; ta -= sweep;
sweep = min(ac, ca);
ans += sweep; ac -= sweep; ca -= sweep;
sweep = min(tc, ct);
ans += sweep; tc -= sweep; ct -= sweep;
int sum = at + ta + ac + ca + tc + ct;
ans += (sum/3)*2;
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... |