Submission #838093

#TimeUsernameProblemLanguageResultExecution timeMemory
838093jasminMutating DNA (IOI21_dna)C++17
100 / 100
36 ms9736 KiB
//IOI 2021 #include<bits/stdc++.h> using namespace std; const int N=1e5+5; int cnta[N][3]; int cntb[N][3]; int ps[N][3][3]; void init(string a, string b){ int n=a.size(); vector<int> enc = {'A', 'C', 'T'}; map<char, int> dec; dec['A']=0; dec['C']=1; dec['T']=2; for(int i=0; i<n; i++){ for(int j=0; j<3; j++){ cnta[i+1][j] = cnta[i][j]; cntb[i+1][j] = cntb[i][j]; if(a[i] == enc[j]){ cnta[i+1][j]++; } if(b[i] == enc[j]){ cntb[i+1][j]++; } } } for(int i=0; i<n; i++){ for(int j=0; j<3; j++){ for(int k=0; k<3; k++){ ps[i+1][j][k] = ps[i][j][k]; } } int j = dec[a[i]]; int k = dec[b[i]]; if(j==k) continue; ps[i+1][j][k]++; } } int get_distance(int x, int y){ for(int j=0; j<3; j++){ if(cnta[y+1][j]-cnta[x][j] != cntb[y+1][j]-cntb[x][j]){ return -1; } } int ans1=0; int ans2=0; for(int j=0; j<3; j++){ for(int k=0; k<j; k++){ int a=ps[y+1][j][k] - ps[x][j][k]; int b=ps[y+1][k][j] - ps[x][k][j]; ans1 += min(a, b); ans2 += max(a, b)-min(a, b); } } assert(ans2%3 == 0); int ans = ans1 + 2*ans2/3; return ans; }
#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...