이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<vector<vector<int>>> pre;
int num(char c){
if(c=='A')return 0;
if(c=='C')return 1;
return 2;
}
void init(string a, string b) {
int n=a.size();
pre=vector<vector<vector<int>>> (n+1,vector<vector<int>>(3,vector<int>(3)));
for(int i=0;i<n;i++){
pre[i+1]=pre[i];
int x,y;
x=num(a[i]);
y=num(b[i]);
pre[i+1][x][y]++;
}
}
vector<vector<int>> sub(vector<vector<int>>& a,vector<vector<int>>& b){
vector<vector<int>> ans(3,vector<int>(3));
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
ans[i][j]=b[i][j]-a[i][j];
}
}
return ans;
}
int get_distance(int x, int y) {
vector<vector<int>> dif=sub(pre[x],pre[y+1]);
int ans=0;
for(int i=0;i<3;i++){
for(int j=i+1;j<3;j++){
if(dif[i][j]){
int d=min(dif[i][j],dif[j][i]);
dif[i][j]-=d;
dif[j][i]-=d;
ans+=d;
}
}
}
//cambios en los que los dos se benefician
//0 1 2
//1 2 0
//2 1 0
int d1=min(dif[0][1],min(dif[1][2],dif[2][0])),d2=min(dif[0][2],min(dif[1][0],dif[2][1]));
ans+=2*d1;
ans+=2*d2;
dif[0][1]-=d1;
dif[1][2]-=d1;
dif[2][0]-=d1;
dif[0][2]-=d2;
dif[1][0]-=d2;
dif[2][1]-=d2;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(dif[i][j]&&i!=j)return -1;
}
}
return ans;
}
/*int main(){
string a,b;
int x,y;
cin>>a>>b;
init(a,b);
while(cin>>x>>y){
cout<<get_distance(x,y)<<'\n';
}
}*/
# | 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... |