Submission #809227

#TimeUsernameProblemLanguageResultExecution timeMemory
809227OAleksaMutating DNA (IOI21_dna)C++17
100 / 100
38 ms8560 KiB
#include <bits/stdc++.h> #include "dna.h" #define f first #define s second using namespace std; const int maxn = 1e5 + 69; vector<int> pa1(maxn), pc1(maxn), pt1(maxn); vector<int> pa2(maxn), pc2(maxn), pt2(maxn); vector<int> at(maxn), ac(maxn), ca(maxn), ct(maxn); vector<int> ta(maxn), tc(maxn); void init(string a, string b) { int n = a.size(); pa1[0] = (a[0] == 'A'); pc1[0] = (a[0] == 'C'); pt1[0] = (a[0] == 'T'); pa2[0] = (b[0] == 'A'); pc2[0] = (b[0] == 'C'); pt2[0] = (b[0] == 'T'); at[0] = (a[0] == 'A' && b[0] == 'T'); ac[0] = (a[0] == 'A' && b[0] == 'C'); ca[0] = (a[0] == 'C' && b[0] == 'A'); ct[0] = (a[0] == 'C' && b[0] == 'T'); ta[0] = (a[0] == 'T' && b[0] == 'A'); tc[0] = (a[0] == 'T' && b[0] == 'C'); for(int i = 1;i < n;i++) { pa1[i] = pa1[i - 1] + (a[i] == 'A'); pc1[i] = pc1[i - 1] + (a[i] == 'C'); pt1[i] = pt1[i - 1] + (a[i] == 'T'); pa2[i] = pa2[i - 1] + (b[i] == 'A'); pc2[i] = pc2[i - 1] + (b[i] == 'C'); pt2[i] = pt2[i - 1] + (b[i] == 'T'); at[i] = at[i - 1] + (a[i] == 'A' && b[i] == 'T'); ac[i] = ac[i - 1] + (a[i] == 'A' && b[i] == 'C'); ca[i] = ca[i - 1] + (a[i] == 'C' && b[i] == 'A'); ct[i] = ct[i - 1] + (a[i] == 'C' && b[i] == 'T'); ta[i] = ta[i - 1] + (a[i] == 'T' && b[i] == 'A'); tc[i] = tc[i - 1] + (a[i] == 'T' && b[i] == 'C'); } } int get_distance(int x, int y) { int ans = 0; int x1 = pa1[y] - (x == 0 ? 0 : pa1[x - 1]); int x2 = pc1[y] - (x == 0 ? 0 : pc1[x - 1]); int x3 = pt1[y] - (x == 0 ? 0 : pt1[x - 1]); int x4 = pa2[y] - (x == 0 ? 0 : pa2[x - 1]); int x5 = pc2[y] - (x == 0 ? 0 : pc2[x - 1]); int x6 = pt2[y] - (x == 0 ? 0 : pt2[x - 1]); if(x1 != x4 || x2 != x5 || x3 != x6) ans = -1; else { int ac1, at1, ca1, ct1, ta1, tc1; ac1 = ac[y] - (x == 0 ? 0 : ac[x - 1]); at1 = at[y] - (x == 0 ? 0 : at[x - 1]); ca1 = ca[y] - (x == 0 ? 0 : ca[x - 1]); ct1 = ct[y] - (x == 0 ? 0 : ct[x - 1]); ta1 = ta[y] - (x == 0 ? 0 : ta[x - 1]); tc1 = tc[y] - (x == 0 ? 0 : tc[x - 1]); if(ac1 < ca1) swap(ac1, ca1); if(at1 < ta1) swap(ta1, at1); if(ct1 < tc1) swap(ct1, tc1); ans += ca1 + ta1 + tc1; ac1 -= ca1; at1 -= ta1; ct1 -= tc1; ca1 = ta1 = tc1 = 0; int a = ac1 + ca1 + ta1 + at1; int c = ca1 + ct1 + ac1 + tc1; int t = ta1 + tc1 + at1 + ct1; ans += max({a, c, t}); } return ans; } // // int main() // { // ios_base::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); // int tt = 1; // //cin >> tt; // while(tt--) { // int n, q; // cin >> n >> q; // string a, b; // cin >> a >> b; // init(a, b); // for(int i = 0;i < q;i++) { // int l, r; // cin >> l >> r; // cout << get_distance(l, r) << endl; // } // } // return 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...