이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <cstdio>
#include <cassert>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int>AtoC,AtoT,CtoT,CtoA,TtoA,TtoC;
void init(std::string a, std::string b) {
int n = (int)a.length();
AtoC.resize(n + 1,0);
CtoT.resize(n + 1,0);
AtoT.resize(n + 1,0);
TtoA.resize(n + 1,0);
CtoA.resize(n + 1,0);
TtoC.resize(n + 1,0);
for (int i = 0;i<n;++i){
if (a[i] == b[i]){
AtoC[i + 1]+=AtoC[i];
AtoT[i + 1]+=AtoT[i];
CtoT[i + 1]+=CtoT[i];
CtoA[i + 1]+=CtoA[i];
TtoA[i + 1]+=TtoA[i];
TtoC[i + 1]+=TtoC[i];
continue;
}
if (a[i] == 'A'){
if (b[i] == 'T'){
AtoT[i + 1]++;
}
else {
AtoC[i + 1]++;
}
}
else if (a[i] == 'T'){
if (b[i] == 'C'){
TtoC[i + 1]++;
}
else {
TtoA[i + 1]++;
}
}
else{
if (b[i] == 'A'){
CtoA[i + 1]++;
}
else {
CtoT[i + 1]++;
}
}
AtoC[i + 1]+=AtoC[i];
AtoT[i + 1]+=AtoT[i];
CtoT[i + 1]+=CtoT[i];
CtoA[i + 1]+=CtoA[i];
TtoA[i + 1]+=TtoA[i];
TtoC[i + 1]+=TtoC[i];
}
}
int get_distance(int x, int y) {
++x;
++y;
int A = 0,C = 0,T = 0;
A+=CtoA[y] - CtoA[x - 1] + TtoA[y] - TtoA[x - 1];
A-=AtoC[y] - AtoC[x - 1] + AtoT[y] - AtoT[x - 1];
C+=AtoC[y] - AtoC[x - 1] + TtoC[y] - TtoC[x - 1];
C-=CtoA[y] - CtoA[x - 1] + CtoT[y] - CtoT[x - 1];
T+=AtoT[y] - AtoT[x - 1] + CtoT[y] - CtoT[x - 1];
T-=TtoA[y] - TtoA[x - 1] + TtoC[y] - TtoC[x - 1];
if (A || T || C)return -1;
int ans = min(AtoC[y] -AtoC[x-1],CtoA[y] - CtoA[x - 1]);
ans+=min(TtoA[y] - TtoA[x - 1],AtoT[y] - AtoT[x - 1]);
ans+=min(CtoT[y] - CtoT[x - 1],TtoC[y] - TtoC[x - 1]);
int tempA = abs(AtoC[y] - AtoC[x - 1] - (CtoA[y] - CtoA[x - 1]));
int tempB = abs(TtoA[y] - TtoA[x - 1] - (AtoT[y] - AtoT[x - 1]));
int tempC = abs(CtoT[y] - CtoT[x - 1] - (TtoC[y] - TtoC[x - 1]));
ans +=((tempA + tempB + tempC + 2)/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... |