Submission #437110

#TimeUsernameProblemLanguageResultExecution timeMemory
437110dqhungdlMutating DNA (IOI21_dna)C++17
100 / 100
50 ms6064 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int n,S[100005][3][3]; int getId(char c) { if(c=='A') return 0; if(c=='C') return 1; return 2; } void init(std::string a, std::string b) { n=a.size(); for(int i=0;i<n;i++) { if(i>0) for(int t1=0;t1<3;t1++) for(int t2=0;t2<3;t2++) S[i][t1][t2]=S[i-1][t1][t2]; S[i][getId(a[i])][getId(b[i])]++; } } int get_distance(int x, int y) { int C[3][3]; for(int t1=0;t1<3;t1++) for(int t2=0;t2<3;t2++) C[t1][t2]=S[y][t1][t2]-(x==0?0:S[x-1][t1][t2]); if(C[0][1]+C[0][2]!=C[1][0]+C[2][0]||C[1][0]+C[1][2]!=C[0][1]+C[2][1]) return -1; int s1=0,s2=1e9; for(int t1=0;t1<3;t1++) for(int t2=t1+1;t2<3;t2++) { int tmp=min(C[t1][t2],C[t2][t1]); C[t1][t2]-=tmp; C[t2][t1]-=tmp; s1+=tmp; } for(int t1=0;t1<3;t1++) for(int t2=t1+1;t2<3;t2++) s2=min(s2,max(C[t1][t2],C[t2][t1])); return s1+2*s2; }
#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...