Submission #438685

#TimeUsernameProblemLanguageResultExecution timeMemory
438685ivan_tudorMutating DNA (IOI21_dna)C++17
100 / 100
65 ms6096 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; const int N = 100005; int comb[N][3][3]; int getcode(char c){ if(c == 'A') return 0; if(c == 'C') return 1; return 2; } void init(std::string a, std::string b) { int n = a.size(); for(int i = 0; i <n; i++){ comb[i][getcode(a[i])][getcode(b[i])] = 1; if(i != 0){ for(int j = 0; j < 3; j++){ for(int k = 0; k < 3; k++) comb[i][j][k] += comb[i-1][j][k]; } } } } int get_distance(int x, int y) { int ans[3][3]; for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ ans[i][j] = comb[y][i][j]; } } x--; if(x>=0){ for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ ans[i][j] -= comb[x][i][j]; } } } int alet[3] = {0, 0, 0}; int blet[3] = {0, 0, 0}; for(int i = 0; i <3; i++){ for(int j = 0; j < 3; j++){ alet[i] += ans[i][j]; blet[j] += ans[i][j]; } } for(int i = 0; i < 3; i++) if(alet[i] != blet[i]) return -1; int rsp = 0; for(int i = 0; i < 3; i++){ for(int j = i +1; j < 3; j++){ int x = min(ans[i][j], ans[j][i]); rsp += x; ans[i][j] -= x; ans[j][i] -= x; } } int val = 0; for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ if(i != j){ if(ans[i][j] != 0) val = ans[i][j]; } } } rsp += 2 * val; return rsp; }
#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...