Submission #774420

#TimeUsernameProblemLanguageResultExecution timeMemory
774420RushBMutating DNA (IOI21_dna)C++17
0 / 100
26 ms7032 KiB
#include "dna.h" #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const int N = 1e5 + 50; int ps[N][3][3], n; inline short T(char c) { switch(c) { case 'A': return 0; case 'T': return 1; default: return 2; } return -1; } void init(string a, string b) { n = a.size(); ps[0][T(a[0])][T(b[0])] = 1; FOR(i, 1, n) { FOR(j, 0, 3) FOR(k, 0, 3) ps[i][j][k] = ps[i - 1][j][k]; ps[i][T(a[i])][T(b[i])]++; } } int get_distance(int x, int y) { int dp[3][3] = {0}; FOR(i, 0, 3) FOR(j, 0, 3) dp[i][j] = ps[y][i][j] - (x ? ps[x - 1][i][j] : 0); int ans = 0; FOR(i, 0, 3) FOR(j, i + 1, 3) { int m = min(dp[i][j], dp[j][i]); ans += m; dp[i][j] -= m; dp[j][i] -= m; } { int m = min({dp[0][1], dp[1][2], dp[2][0]}); ans += 2 * m; dp[0][1] -= m, dp[1][2] -= m, dp[2][0] -= m; } { int m = min({dp[0][2], dp[2][1], dp[1][0]}); ans += 2 * m; dp[0][2] -= m, dp[2][1] -= m, dp[1][0] -= m; } FOR(i, 0, 3) FOR(j, 0, 3) if (dp[i][j]) return -1; 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...