Submission #970761

#TimeUsernameProblemLanguageResultExecution timeMemory
970761elotelo966Mutating DNA (IOI21_dna)C++17
100 / 100
37 ms8968 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; #define lim 100005 int n; int pre_a_a[lim],pre_b_a[lim];// a string a char ----- b string a char int pre_a_t[lim],pre_b_t[lim];// a string t char ----- b string t char int pre_a_c[lim],pre_b_c[lim];// a string c char ----- b string c char int at[lim],ta[lim],ac[lim],ca[lim],tc[lim],ct[lim]; int sum[lim]; inline bool querya(int x,int y){ if(pre_a_a[y+1]-pre_a_a[x]==pre_b_a[y+1]-pre_b_a[x])return 1; return 0; } inline bool queryt(int x,int y){ if(pre_a_t[y+1]-pre_a_t[x]==pre_b_t[y+1]-pre_b_t[x])return 1; return 0; } inline bool queryc(int x,int y){ if(pre_a_c[y+1]-pre_a_c[x]==pre_b_c[y+1]-pre_b_c[x])return 1; return 0; } void init(string a,string b) { n=a.length(); for(int i=0;i<n;i++){ pre_a_a[i+1]=pre_a_a[i]; if(a[i]=='A')pre_a_a[i+1]++; pre_b_a[i+1]=pre_b_a[i]; if(b[i]=='A')pre_b_a[i+1]++; pre_a_t[i+1]=pre_a_t[i]; if(a[i]=='T')pre_a_t[i+1]++; pre_b_t[i+1]=pre_b_t[i]; if(b[i]=='T')pre_b_t[i+1]++; pre_a_c[i+1]=pre_a_c[i]; if(a[i]=='C')pre_a_c[i+1]++; pre_b_c[i+1]=pre_b_c[i]; if(b[i]=='C')pre_b_c[i+1]++; sum[i+1]=sum[i]; if(a[i]!=b[i])sum[i+1]++; ac[i+1]=ac[i],at[i+1]=at[i]; ca[i+1]=ca[i],ct[i+1]=ct[i]; ta[i+1]=ta[i],tc[i+1]=tc[i]; if(a[i]=='A'){ if(b[i]=='C')ac[i+1]++; else if(b[i]=='T')at[i+1]++; } else if(a[i]=='C'){ if(b[i]=='A')ca[i+1]++; else if(b[i]=='T')ct[i+1]++; } else{ if(b[i]=='A')ta[i+1]++; else if(b[i]=='C')tc[i+1]++; } } } int get_distance(int x, int y) { if(querya(x,y) && queryt(x,y) && queryc(x,y)){ int cev=0; int anormal=sum[y+1]-sum[x]; cev+=min(at[y+1]-at[x],ta[y+1]-ta[x]); cev+=min(ac[y+1]-ac[x],ca[y+1]-ca[x]); cev+=min(tc[y+1]-tc[x],ct[y+1]-ct[x]); anormal-=cev*2; cev+=(anormal/3)*2; return cev; } else return -1; }
#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...