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;
const int MXN = 100100;
int zac[MXN], zat[MXN], zca[MXN], zct[MXN], zta[MXN], ztc[MXN];
void init(string a, string b){
int n = a.size();
for(int i=1; i<=n; i++){
zac[i]+= zac[i-1], zat[i]+= zat[i-1];
zca[i]+= zca[i-1], zct[i]+= zct[i-1];
zta[i]+= zta[i-1], ztc[i]+= ztc[i-1];
char A = a[i-1], B = b[i-1];
if(A == 'A'){
if(B == 'C') zac[i]++;
if(B == 'T') zat[i]++;
}
if(A == 'C'){
if(B == 'A') zca[i]++;
if(B == 'T') zct[i]++;
}
if(A == 'T'){
if(B == 'A') zta[i]++;
if(B == 'C') ztc[i]++;
}
}
}
int get_distance(int x, int y){
int qac = zac[y+1]-zac[x], qat = zat[y+1]-zat[x];
int qca = zca[y+1]-zca[x], qct = zct[y+1]-zct[x];
int qta = zta[y+1]-zta[x], qtc = ztc[y+1]-ztc[x];
if(qac+qat != qca+qta) return -1;
if(qca+qct != qac+qtc) return -1;
if(qta+qtc != qat+qct) return -1;
// correcting two letters per swap
int acca = min(qac, qca);
qac-= acca, qca-= acca;
int atta = min(qat, qta);
qat-= atta, qta-= atta;
int cttc = min(qct, qtc);
qct-= cttc, qtc-= cttc;
return acca + atta + cttc + 2*max(qac, qca);
}
# | 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... |