Submission #556962

#TimeUsernameProblemLanguageResultExecution timeMemory
556962AlexandruabcdeMutating DNA (IOI21_dna)C++17
100 / 100
54 ms8596 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; constexpr int NMAX = 1e5 + 5; int N; int pref[NMAX][3][3]; int fr[NMAX][3]; int Value (char ch) { if (ch == 'A') return 0; if (ch == 'C') return 1; return 2; } void init(std::string a, std::string b) { N = a.size(); for (int i = 1; i <= N; ++ i ) { pref[i][Value(a[i-1])][Value(b[i-1])] = 1; for (int j = 0; j < 3; ++ j ) for (int k = 0; k < 3; ++ k ) pref[i][j][k] += pref[i-1][j][k]; fr[i][Value(a[i-1])] ++; fr[i][Value(b[i-1])] --; for (int j = 0; j < 3; ++ j ) fr[i][j] += fr[i-1][j]; } } int get_distance(int x, int y) { int mat[3][3]; memset(mat, 0, sizeof(mat)); int freq[3]; memset(freq, 0, sizeof(freq)); for (int i = 0; i < 3; ++ i ) for (int j = 0; j < 3; ++ j ) mat[i][j] = pref[y+1][i][j] - pref[x][i][j]; for (int i = 0; i < 3; ++ i ) freq[i] = fr[y+1][i] - fr[x][i]; bool ok = 1; for (int i = 0; i < 3; ++ i ) if (freq[i] != 0) ok = 0; if (!ok) return -1; int ans = 0; for (int i = 0; i < 3; ++ i ) { for (int j = i+1; j < 3; ++ j ) { int value = min(mat[i][j], mat[j][i]); ans = ans + value; mat[i][j] -= value; mat[j][i] -= value; } } int Max = 0; for (int i = 0; i < 3; ++ i ) { for (int j = 0; j < 3; ++ j ) { if (i == j) continue; Max = max(Max, mat[i][j]); } } return ans + 2 * Max; }
#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...