Submission #523011

#TimeUsernameProblemLanguageResultExecution timeMemory
523011marat0210Mutating DNA (IOI21_dna)C++17
0 / 100
52 ms12136 KiB
#include <dna.h> #include <bits/stdc++.h> using namespace std; vector <int> posa, posb; const int N = 500500; vector <int> prefa(N), preft(N), prefc(N); int values[2][3][N]; 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 va = 0, vt = 0, vc = 0; for (int i = 0; i < n; ++i) { if ((posa[i] == 0 and posb[i] != 0) or (posb[i] == 0 and posa[i] != 0)) { va++; prefa[i] = va; } else if (posa[i] != 0 or posb[i] != 0) { if (i > 0) { prefa[i] = prefa[i - 1]; } } if ((posa[i] == 1 and posb[i] != 1) or (posa[i] != 1 and posb[i] == 1)) { vt++; preft[i] = vt; } else if (posa[i] != 1 or posb[i] != 1) { if (i > 0) { preft[i] = preft[i - 1]; } } if ((posa[i] == 2 and posb[i] != 2) or (posa[i] != 2 and posb[i] == 2)) { vc++; prefc[i] = vc; } else if (posa[i] != 2 or posb[i] != 2) { if (i > 0) { prefc[i] = prefc[i - 1]; } } } int cnta = 0, cntt = 0, cntc = 0; for (int i = 0; i < n; ++i) { if (posa[i] == 0) { cnta++; values[0][0][i] = cnta; if (i > 0) { values[0][1][i] = values[0][1][i - 1]; values[0][2][i] = values[0][2][i - 1]; } } else if (posa[i] == 1) { cntt++; values[0][1][i] = cntt; if (i > 0) { values[0][0][i] = values[0][0][i - 1]; values[0][2][i] = values[0][2][i - 1]; } } else if (posa[i] == 2) { cntc++; values[0][2][i] = cntc; if (i > 0) { values[0][0][i] = values[0][0][i - 1]; values[0][1][i] = values[0][1][i - 1]; } } } cnta = 0, cntt = 0, cntc = 0; for (int i = 0; i < n; ++i) { if (posb[i] == 0) { cnta++; values[1][0][i] = cnta; if (i > 0) { values[1][1][i] = values[1][1][i - 1]; values[1][2][i] = values[1][2][i - 1]; } } else if (posb[i] == 1) { cntt++; values[1][1][i] = cntt; if (i > 0) { values[1][0][i] = values[1][0][i - 1]; values[1][2][i] = values[1][2][i - 1]; } } else if (posb[i] == 2) { cntc++; values[1][2][i] = cntc; if (i > 0) { values[1][0][i] = values[1][0][i - 1]; values[1][1][i] = values[1][1][i - 1]; } } } } int get_distance(int x, int y) { if (y - x == 0) { if (posa[x] == posb[x]) { return 0; } else { return -1; } } else { int cnta = 0, cntt = 0, cntc = 0; bool ok = false; if (x == 0) { cnta = values[0][0][y] - values[1][0][y]; cntt = values[0][1][y] - values[1][1][y]; cntc = values[0][2][y] - values[1][2][y]; } else { cnta = values[0][0][y] - values[0][0][x - 1] - values[1][0][y] + values[1][0][x - 1]; cntt = values[0][1][y] - values[0][1][x - 1] - values[1][1][y] + values[1][1][x - 1]; cntc = values[0][2][y] - values[0][2][x - 1] - values[1][2][y] + values[1][2][x - 1]; } if (cnta != 0 or cntt != 0 or cntc != 0) { return -1; } if (values[0][2][y] > 0) { ok = true; } if (!ok) { int res = 0; if (x == 0) { res = prefa[y] / 2; } else { res = (prefa[y] - prefa[x - 1]) / 2; } return res; } cnta = 0, cntt = 0, cntc = 0; for (int i = x; i <= y; ++i) { if ((posa[i] == 0 and posb[i] != 0) or (posa[i] != 0 and posb[i] == 0)) { cnta++; } if ((posa[i] == 1 and posb[i] != 1) or (posa[i] != 1 and posb[i] == 1)) { cntt++; } if ((posa[i] == 2 and posb[i] != 2) or (posa[i] != 2 and posb[i] == 2)) { cntc++; } } vector <int> temp = {cnta, cntt, cntc}; sort(temp.begin(), temp.end()); int res = 0; int vx = temp[1] / 2; res += vx; temp[2] -= 2 * vx; if (temp[1] % 2 == 1) { temp[1] = 1; } else { temp[1] = 0; } if (temp[0] >= temp[2]) { vx = temp[2] / 2; res += vx; temp[0] -= 2 * vx; temp[2] -= 2 * vx; } else { vx = temp[0] / 2; res += vx; temp[0] -= 2 * vx; temp[2] -= 2 * vx; } sort(temp.begin(), temp.end()); if (temp[0] == 1 and temp[1] == 1 and temp[2] == 1) { res += 2; } else if (temp[0] + temp[1] + temp[2] >= 1) { res += 1; } 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...