Submission #839303

#TimeUsernameProblemLanguageResultExecution timeMemory
839303mihaibunMutating DNA (IOI21_dna)C++17
100 / 100
29 ms7380 KiB
using namespace std; #include "dna.h" int n,C[4][4][100003]; void init(string a, string b) { n = a.size(); for(int i = 1; i <= 3; i++) for(int j = 1; j <= 3; j++) C[i][j][0] = 0; for(int i = 0; i < n; i++){ if((a[i]=='A')and(b[i]=='A')) C[1][1][i+1] = C[1][1][i]+1; else C[1][1][i+1] = C[1][1][i]; if((a[i]=='T')and(b[i]=='T')) C[2][2][i+1] = C[2][2][i]+1; else C[2][2][i+1] = C[2][2][i]; if((a[i]=='C')and(b[i]=='C')) C[3][3][i+1] = C[3][3][i]+1; else C[3][3][i+1] = C[3][3][i]; if((a[i]=='A')and(b[i]=='T')) C[1][2][i+1] = C[1][2][i]+1; else C[1][2][i+1] = C[1][2][i]; if((a[i]=='A')and(b[i]=='C')) C[1][3][i+1] = C[1][3][i]+1; else C[1][3][i+1] = C[1][3][i]; if((a[i]=='T')and(b[i]=='A')) C[2][1][i+1] = C[2][1][i]+1; else C[2][1][i+1] = C[2][1][i]; if((a[i]=='T')and(b[i]=='C')) C[2][3][i+1] = C[2][3][i]+1; else C[2][3][i+1] = C[2][3][i]; if((a[i]=='C')and(b[i]=='A')) C[3][1][i+1] = C[3][1][i]+1; else C[3][1][i+1] = C[3][1][i]; if((a[i]=='C')and(b[i]=='T')) C[3][2][i+1] = C[3][2][i]+1; else C[3][2][i+1] = C[3][2][i]; } } int get_distance(int x, int y) { int sol = 0,xa,ya,z,u,v,t; xa = C[1][1][y+1]+C[1][2][y+1]+C[1][3][y+1]-C[1][1][x]-C[1][2][x]-C[1][3][x]; ya = C[2][1][y+1]+C[2][2][y+1]+C[2][3][y+1]-C[2][1][x]-C[2][2][x]-C[2][3][x]; z = C[3][1][y+1]+C[3][2][y+1]+C[3][3][y+1]-C[3][1][x]-C[3][2][x]-C[3][3][x]; u = C[1][1][y+1]+C[2][1][y+1]+C[3][1][y+1]-C[1][1][x]-C[2][1][x]-C[3][1][x]; v = C[2][2][y+1]+C[3][2][y+1]+C[1][2][y+1]-C[2][2][x]-C[3][2][x]-C[1][2][x]; t = C[1][3][y+1]+C[2][3][y+1]+C[3][3][y+1]-C[1][3][x]-C[2][3][x]-C[3][3][x]; if((xa==u)and(ya==v)and(z==t)){ sol = min(C[1][2][y+1]-C[1][2][x],C[2][1][y+1]-C[2][1][x]); sol += min(C[1][3][y+1]-C[1][3][x],C[3][1][y+1]-C[3][1][x]); sol += min(C[3][2][y+1]-C[3][2][x],C[2][3][y+1]-C[2][3][x]); sol += 2*(max(C[1][2][y+1]-C[1][2][x],C[2][1][y+1]-C[2][1][x])-min(C[1][2][y+1]-C[1][2][x],C[2][1][y+1]-C[2][1][x])); } else sol = -1; return sol; }
#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...