Submission #623821

#TimeUsernameProblemLanguageResultExecution timeMemory
623821IwanttobreakfreeMutating DNA (IOI21_dna)C++17
35 / 100
87 ms23500 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=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 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...