Submission #490540

#TimeUsernameProblemLanguageResultExecution timeMemory
490540sliviuMutating DNA (IOI21_dna)C++17
56 / 100
44 ms6020 KiB
#include <bits/stdc++.h> using namespace std; int n, c[100001][3][3]; int val(char x) { return x == 'A' ? 0 : x == 'T' ? 1 : 2; } void init(string a, string b) { n = a.length(); for (int i = 0; i < n; ++i) { ++c[i + 1][val(a[i])][val(b[i])]; for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) c[i + 1][j][k] += c[i][j][k]; } } int get_distance(int x, int y) { int left = y - x + 1, swaps = 0; for (int i = 0; i < 3; ++i) left -= c[y + 1][i][i] - c[x][i][i]; for (int i = 0; i < 3; ++i) for (int j = i + 1; j < 3; ++j) { int off = min(c[y + 1][i][j] - c[x][i][j], c[y + 1][j][i] - c[x][j][i]); left -= 2 * off, swaps += off; } int a = n, b = n; for (int i = 0; i < 3; ++i) a = min(a, c[y + 1][i][(i + 1) % 3] - c[x][i][(i + 1) % 3]), b = min(b, c[y + 1][(i + 1) % 3][i] - c[x][(i + 1) % 3][i]); left -= 3 * (a + b), swaps += 2 * (a + b); if (left) return -1; return swaps; }
#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...