Submission #521621

#TimeUsernameProblemLanguageResultExecution timeMemory
521621marat0210Mutating DNA (IOI21_dna)C++17
43 / 100
1566 ms3172 KiB
#include <dna.h> #include <bits/stdc++.h> using namespace std; vector <int> posa, posb; void init(string a, string b) { int n = a.size(); for (int i = 0; i < n; ++i) { if (a[i] == 'A') { posa.push_back(0); } else if (a[i] == 'T') { posa.push_back(1); } else if (a[i] == 'C') { posa.push_back(2); } if (b[i] == 'A') { posb.push_back(0); } else if (b[i] == 'T') { posb.push_back(1); } else if (b[i] == 'C') { posb.push_back(2); } } } int get_distance(int x, int y) { if (y - x == 2) { bool ok = true; for (int i = x; i <= y; ++i) { if (posa[i] != posb[i]) { ok = false; break; } } if (ok) { return 0; } int cnta = 0, cntt = 0, cntc = 0; for (int i = x; i <= y; ++i) { if (posa[i] == 0) { cnta++; } else if (posa[i] == 1) { cntt++; } else { cntc++; } } for (int i = x; i <= y; ++i) { if (posb[i] == 0) { cnta--; } else if (posb[i] == 1) { cntt--; } else { cntc--; } } if (cnta != 0 or cntt != 0 or cntc != 0) { return -1; } ok = false; for (int i = x; i <= y; ++i) { if (posa[i] == posb[i]) { ok = true; break; } } if (ok) { return 1; } else { return 2; } } else if (y - x == 1) { if (posa[x] == posb[x] and posa[y] == posb[y]) { return 0; } else if (posa[x] == posb[y] and posb[x] == posa[y]) { return 1; } else { return -1; } } else if (y - x == 0) { if (posa[x] == posb[x]) { return 0; } else { return -1; } } else { int cnta = 0, cntt = 0, cntc = 0; bool seen = false; for (int i = x; i <= y; ++i) { if (posa[i] == 0) { cnta++; } else if (posa[i] == 2) { cntc++; seen = true; } else { cntt++; } } for (int i = x; i <= y; ++i) { if (posb[i] == 0) { cnta--; } else if (posb[i] == 2) { cntc--; } else { cntt--; } } if (cnta != 0 or cntt != 0 or cntc != 0) { return -1; } int cnt = 0; for (int i = x; i <= y; ++i) { if (posa[i] != posb[i]) { cnt++; } } int res = (cnt + 1) / 2; if (seen) { int cnt0 = 0, cnt1 = 0, cnt2 = 0; for (int i = x; i <= y; ++i) { if (posa[i] == 0) { cnt0++; } else if (posa[i] == 1) { cnt1++; } else { cnt2++; } } for (int i = x; i <= y; ++i) { if (posa[i] == posb[i]) { if (posa[i] == 0) { cnt0--; } else if (posa[i] == 1) { cnt1--; } else { cnt2--; } } } if (cnt0 >= cnt1) { res += cnt1; cnt0 -= cnt1; if (cnt0 >= cnt2) { res += cnt0; } else { res += cnt2; } } else { res += cnt0; cnt1 -= cnt0; if (cnt1 >= cnt2) { res += cnt1; } else { res += cnt2; } } } return res; } }
#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...