Submission #490541

#TimeUsernameProblemLanguageResultExecution timeMemory
490541sliviuMutating DNA (IOI21_dna)C++17
100 / 100
35 ms7412 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; int cur[3][3]; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cur[i][j] = c[y + 1][i][j] - c[x][i][j]; for (int i = 0; i < 3; ++i) left -= cur[i][i]; for (int i = 0; i < 3; ++i) for (int j = i + 1; j < 3; ++j) { int off = min(cur[i][j], cur[j][i]); cur[i][j] -= off, cur[j][i] -= off; left -= 2 * off, swaps += off; } int a = n, b = n; for (int i = 0; i < 3; ++i) a = min(a, cur[i][(i + 1) % 3]), b = min(b, cur[(i + 1) % 3][i]); for (int i = 0; i < 3; ++i) cur[i][(i + 1) % 3] -= a, cur[(i + 1) % 3][i] -= b; 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...