Submission #444862

#TimeUsernameProblemLanguageResultExecution timeMemory
444862apostoldaniel854Mutating DNA (IOI21_dna)C++17
100 / 100
57 ms7396 KiB
#include "dna.h" #include <map> #include <vector> #include <bits/stdc++.h> using ll = long long; #define dbg(x) std::cerr << #x << " " << x << "\n" const int MAX_N = 1e5; int sum[MAX_N][3][3]; void init(std::string a, std::string b) { std::map <char, int> mp; mp['A'] = 0, mp['C'] = 1, mp['T'] = 2; int n = a.size (); for (int i = 0; i < n; i++) { if (i > 0) { for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) sum[i][j][k] += sum[i - 1][j][k]; } sum[i][mp[a[i]]][mp[b[i]]]++; } } int cnt[3][3]; int get_distance(int x, int y) { std::vector <int> freqA (3, 0), freqB (3, 0); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cnt[i][j] = sum[y][i][j]; if (x > 0) { cnt[i][j] -= sum[x - 1][i][j]; } // dbg (i); dbg (j); dbg (cnt[i][j]); freqA[i] += cnt[i][j]; freqB[j] += cnt[i][j]; } } for (int i = 0; i < 3; i++) if (freqA[i] != freqB[i]) return -1; int ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { int sub = std::min (cnt[i][j], cnt[j][i]); ans += sub; cnt[i][j] -= sub; cnt[j][i] -= sub; } } int to_add = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j && cnt[i][j]) { to_add = cnt[i][j]; } } } ans += 2 * to_add; 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...