Submission #1322888

#TimeUsernameProblemLanguageResultExecution timeMemory
1322888tkm_algorithmsMutating DNA (IOI21_dna)C++20
0 / 100
26 ms5452 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define rep(i, l, n) for (int i = l; i < (n); ++i) #define sz(x) (int)x.size() const char nl = '\n'; const int mod = 1e9+7; const int NMAX = 1e5+10; const int inf = 1e9+10; int p0[2][NMAX], p1[2][NMAX], p2[2][NMAX]; int N, res[NMAX]; string s, t; void init(string a, string b) { N = sz(a); s = a, t = b; rep(i, 0, 2) rep(j, 0, N) { if (i == 0) { if (a[j] == 'A')p0[0][j] += 1; if (a[j] == 'C')p1[0][j] += 1; if (a[j] == 'T')p2[0][j] += 1; } else { if (b[j] == 'A')p0[1][j] += 1; if (b[j] == 'C')p1[1][j] += 1; if (b[j] == 'T')p2[1][j] += 1; } if (j) { p0[i][j] += p0[i][j-1]; p1[i][j] += p1[i][j-1]; p2[i][j] += p2[i][j-1]; } } vector<int> nol, bir, iki; rep(i, 0, N) { if (a[i] == 'A')nol.push_back(i); if (a[i] == 'C')bir.push_back(i); if (a[i] == 'T')iki.push_back(i); } for (int i = N-1; i >= 0; --i) { if (b[i] == 'A') { if (nol.empty())continue; res[i] = 1; nol.pop_back(); } if (b[i] == 'C') { if (bir.empty())continue; res[i] = 1; bir.pop_back(); } if (b[i] == 'A') { if (iki.empty())continue; res[i] = 1; iki.pop_back(); } if (i<N-1)res[i] += res[i+1]; } } int get_distance(int x, int y) { bool ok = true; //rep(i, 0, 3) { int a = p0[0][y]-(x?p0[0][x-1]:0); int b = p0[1][y]-(x?p0[1][x-1]:0); ok &= (b==a); //} a = p1[0][y]-(x?p1[0][x-1]:0); b = p1[1][y]-(x?p1[1][x-1]:0); ok &= (b==a); a = p2[0][y]-(x?p2[0][x-1]:0); b = p2[1][y]-(x?p2[1][x-1]:0); ok &= (b==a); if (!ok)return -1; vector<int> nol, bir, iki; int ans = 0; rep(i, x, y+1) { if (s[i] == 'A')nol.push_back(i); if (s[i] == 'C')bir.push_back(i); if (s[i] == 'T')iki.push_back(i); } for (int i = y; i >= x; --i) { if (!nol.empty() && nol.back() > i)nol.pop_back(); if (!bir.empty() && bir.back() > i)bir.pop_back(); if (!iki.empty() && iki.back() > i)iki.pop_back(); if (t[i] == 'A') { if (nol.empty())continue; ans += 1; nol.pop_back(); } if (t[i] == 'C') { if (bir.empty())continue; ans += 1; bir.pop_back(); } if (t[i] == 'T') { if (iki.empty())continue; ans += 1; iki.pop_back(); } } return ans; //return res[x]-(y+1<N?res[y+1]:0); }
#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...