이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |