Submission #623823

#TimeUsernameProblemLanguageResultExecution timeMemory
623823IwanttobreakfreeMutating DNA (IOI21_dna)C++17
100 / 100
91 ms23472 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...