이 제출은 이전 버전의 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=0;j<3;j++){
if(i==j)continue;
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
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... |