Submission #818134

#TimeUsernameProblemLanguageResultExecution timeMemory
818134alvingogoMutating DNA (IOI21_dna)C++17
100 / 100
76 ms8436 KiB
#include "dna.h" #include <bits/stdc++.h> #define fs first #define sc second #define p_q priority_queue using namespace std; int n; vector<int> pre[3][3],pre2[3],pre3[3]; void init(string a, string b) { map<char,int> m; m['A']=0; m['C']=1; m['T']=2; n=a.length(); for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ pre[i][j].resize(n); } pre2[i].resize(n); pre3[i].resize(n); } for(int i=0;i<n;i++){ pre[m[a[i]]][m[b[i]]][i]++; pre2[m[a[i]]][i]++; pre3[m[b[i]]][i]++; } for(int i=1;i<n;i++){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ pre[j][k][i]+=pre[j][k][i-1]; } pre2[j][i]+=pre2[j][i-1]; pre3[j][i]+=pre3[j][i-1]; } } } int get_distance(int x, int y) { int z[3][3]={0},s[3]={0}; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ z[i][j]=pre[i][j][y]; if(x){ z[i][j]-=pre[i][j][x-1]; } } s[i]+=pre2[i][y]; s[i]-=pre3[i][y]; if(x){ s[i]-=pre2[i][x-1]; s[i]+=pre3[i][x-1]; } } if(s[0] || s[1] || s[2]){ return -1; } int ans=0; ans+=min(z[0][1],z[1][0]); ans+=min(z[0][2],z[2][0]); ans+=min(z[1][2],z[2][1]); int a=z[1][0]+z[0][1]-2*min(z[0][1],z[1][0]); int b=z[1][2]+z[2][1]-2*min(z[2][1],z[1][2]); int c=z[2][0]+z[0][2]-2*min(z[0][2],z[2][0]); if(a!=b || b!=c){ return -1; } return ans+2*a; }
#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...