Submission #552816

#TimeUsernameProblemLanguageResultExecution timeMemory
552816JomnoiMutating DNA (IOI21_dna)C++17
100 / 100
59 ms13232 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; const int MAX_N = 1e5 + 10; int preA[3][MAX_N], preB[3][MAX_N]; int preAB[3][3][MAX_N], preBA[3][3][MAX_N]; void init(string a, string b) { map <char, int> mp; mp['A'] = 0, mp['C'] = 1, mp['T'] = 2; int N = a.length(); for(int i = 1; i <= N; i++) { for(int j = 0; j < 3; j++) { preA[j][i] = preA[j][i - 1]; preB[j][i] = preB[j][i - 1]; for(int k = 0; k < 3; k++) { preAB[j][k][i] += preAB[j][k][i - 1]; preBA[j][k][i] += preBA[j][k][i - 1]; } } preA[mp[a[i - 1]]][i]++; preB[mp[b[i - 1]]][i]++; preAB[mp[a[i - 1]]][mp[b[i - 1]]][i]++; preBA[mp[b[i - 1]]][mp[a[i - 1]]][i]++; } } int range(int x, int y, int *a) { return a[y + 1] - a[x]; } int get_distance(int x, int y) { for(int i = 0; i < 3; i++) { if(range(x, y, preA[i]) != range(x, y, preB[i])) { return -1; } } int ans = 0, tmp = 0; for(int i = 0; i < 3; i++) { for(int j = i + 1; j < 3; j++) { int L = range(x, y, preAB[i][j]), R = range(x, y, preBA[i][j]); ans += min(L, R); tmp += max(L, R) - min(L, R); } } return ans + tmp * 2 / 3; }
#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...