Submission #549956

#TimeUsernameProblemLanguageResultExecution timeMemory
549956CyberSleeperMutating DNA (IOI21_dna)C++17
100 / 100
43 ms10176 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; char gen[]={'A', 'T', 'C'}; int N, diff[100007], pref[3][3][100007], prefA[3][100007], prefB[3][100007]; int getD(int x){ if(x>=0) return diff[x]; return 0; } int getP(int x, int y, int z){ if(z>=0) return pref[x][y][z]; return 0; } int getA(int x, int y){ if(y>=0) return prefA[x][y]; return 0; } int getB(int x, int y){ if(y>=0) return prefB[x][y]; return 0; } void init(std::string a, std::string b) { N=a.size(); for(int i=0; i<N; i++){ diff[i]=(a[i]!=b[i])+getD(i-1); for(int j=0; j<3; j++){ prefA[j][i]=(a[i]==gen[j])+getA(j, i-1); prefB[j][i]=(b[i]==gen[j])+getB(j, i-1); for(int k=0; k<3; k++){ pref[j][k][i]=((a[i]==gen[j])&&(b[i]==gen[k]))+getP(j, k, i-1); } } } } int get_distance(int x, int y){ int sisa=0, ans=0; for(int i=0; i<3; i++){ if((getA(i, y)-getA(i, x-1))!=(getB(i, y)-getB(i, x-1))) return -1; for(int j=i+1, tmp; j<3; j++){ if(i!=j){ tmp=min(getP(i, j, y)-getP(i, j, x-1), getP(j, i, y)-getP(j, i, x-1)); ans+=tmp; sisa+=max(getP(i, j, y)-getP(i, j, x-1), getP(j, i, y)-getP(j, i, x-1))-tmp; } } } return ans+sisa*2/3; return 0; }
#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...