Submission #829866

#TimeUsernameProblemLanguageResultExecution timeMemory
829866Sohsoh84Mutating DNA (IOI21_dna)C++17
100 / 100
31 ms8628 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define sep ' ' #define debug(x) cerr << #x << ": " << x << endl; const int MAXN = 1e6 + 10; int n, ps[MAXN], c1[MAXN], c2[MAXN], f[MAXN][3][3]; inline int r(char x) { if (x == 'A') return 0; if (x == 'T') return 1; return 2; } void init(string a, string b) { n = a.size(); a = '#' + a; b = '#' + b; for (int i = 1; i <= n; i++) { ps[i] = ps[i - 1] + (a[i] != b[i]); c1[i] = c1[i - 1] + (a[i] == 'A') - (b[i] == 'A'); c2[i] = c2[i - 1] + (a[i] == 'T') - (b[i] == 'T'); for (int a = 0; a < 3; a++) for (int b = 0; b < 3; b++) f[i][a][b] = f[i - 1][a][b]; f[i][r(a[i])][r(b[i])]++; } } int get_distance(int x, int y) { x++; y++; if (c1[y] - c1[x - 1] || c2[y] - c2[x - 1]) return -1; int ans = 0; int ms = ps[y] - ps[x - 1]; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { int c = min(f[y][i][j] - f[x - 1][i][j], f[y][j][i] - f[x - 1][j][i]); ms -= 2 * c; ans += c; } } ans += ms * 2 / 3; 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...