Submission #829971

#TimeUsernameProblemLanguageResultExecution timeMemory
829971alex_2008Mutating DNA (IOI21_dna)C++17
100 / 100
37 ms6752 KiB
#include "dna.h" #include <iostream> #include <cmath> #include <algorithm> #include <vector> typedef long long ll; using namespace std; const int N = 1e5 + 10; int cnt[N][3][3]; int f(char x) { if (x == 'A') return 0; if (x == 'C') return 1; return 2; } void init(string a, string b) { int n = (int)a.size(); for (int i = 1; i <= n; i++) { for (int j = 0; j <= 2; j++) { for (int k = 0; k <= 2; k++) { cnt[i][j][k] = cnt[i - 1][j][k]; } } cnt[i][f(a[i - 1])][f(b[i - 1])]++; } } int get_distance(int x, int y) { ++x; ++y; int cntab = cnt[y][0][1] - cnt[x - 1][0][1], cntac = cnt[y][0][2] - cnt[x - 1][0][2], cntba = cnt[y][1][0] - cnt[x - 1][1][0], cntbc = cnt[y][1][2] - cnt[x - 1][1][2], cntca = cnt[y][2][0] - cnt[x - 1][2][0], cntcb = cnt[y][2][1] - cnt[x - 1][2][1]; if (cntab + cntac != cntba + cntca) return -1; if (cntba + cntbc != cntab + cntcb) return -1; if (cntca + cntcb != cntac + cntbc) return -1; int ans = 0; int u = min(cntab, cntba); cntab -= u; cntba -= u; ans += u; u = min(cntac, cntca); cntac -= u; cntca -= u; ans += u; u = min(cntbc, cntcb); cntbc -= u; cntcb -= u; ans += u; int l = cntab + cntac + cntba + cntbc + cntca + cntcb; l = 2 * l; l /= 3; ans += l; 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...