Submission #623837

#TimeUsernameProblemLanguageResultExecution timeMemory
623837a_aguiloMutating DNA (IOI21_dna)C++17
100 / 100
293 ms29440 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; vector<vector<int>> tree; int n; //type [0] = A vs T //type [1] = T vs A //type [2] = C vs T //type [3] = T vs C //type [4] = A vs C //type [5] = C vs A void buildTree (int node, int left, int right, vector<vector<int>>& arr){ if(left > right) return; if(left == right){ tree[node] = arr[left]; return; } int mid = left + (right - left)/2; buildTree(2*node, left, mid, arr); buildTree(2*node+1, mid+1, right, arr); tree[node][0] = tree[2*node][0] + tree[2*node+1][0]; tree[node][1] = tree[2*node][1] + tree[2*node+1][1]; tree[node][2] = tree[2*node][2] + tree[2*node+1][2]; tree[node][3] = tree[2*node][3] + tree[2*node+1][3]; tree[node][4] = tree[2*node][4] + tree[2*node+1][4]; tree[node][5] = tree[2*node][5] + tree[2*node+1][5]; } vector<int> getValue (int node, int left, int right, int x, int y){ if(x > right or y < left) return {0, 0, 0, 0, 0, 0}; if(x <= left and y >= right) return tree[node]; int mid = left + (right - left)/2; vector<int> l = getValue(2*node, left, mid, x, y); vector<int> r = getValue(2*node+1, mid+1, right, x, y); vector<int> ans(6); for(int i = 0; i < 6; ++i) ans[i] = l[i] + r[i]; return ans; } void init(string a, string b) { n = a.size(); vector<vector<int>> arr(a.size(), vector<int>(6, 0)); for (int i = 0; i < a.size(); ++i){ if(a[i] != b[i]){ if(a[i] == 'A' and b[i] == 'T') arr[i][0] = 1; if(a[i] == 'T' and b[i] == 'A') arr[i][1] = 1; if(a[i] == 'C' and b[i] == 'T') arr[i][2] = 1; if(a[i] == 'T' and b[i] == 'C') arr[i][3] = 1; if(a[i] == 'A' and b[i] == 'C') arr[i][4] = 1; if(a[i] == 'C' and b[i] == 'A') arr[i][5] = 1; } } tree = vector<vector<int>> (4*a.size(), vector<int>(6, 0)); buildTree(1, 0, a.size()-1, arr); } int get_distance(int x, int y) { vector<int> ans = getValue(1, 0, n-1, x, y); long long resp = 0; int AT = ans[0]; int TA = ans[1]; int CT = ans[2]; int TC = ans[3]; int AC = ans[4]; int CA = ans[5]; int Aa = AT + AC; int Ta = TA + TC; int Ca = CA + CT; int Ab = TA + CA; int Cb = AC + TC; int Tb = AT + CT; if(Aa == Ab and Ca == Cb and Ta == Tb) { if(AT> TA){ resp += (long long)TA; AT -= TA; TA = 0; TC -= AT; AC += AT; resp += (long long)AT; AT = 0; } else if (AT == TA){ resp += (long long) TA; AT = TA = 0; } else{ resp += (long long)AT; TA -= AT; AT = 0; AC -= TA; TC += TA; resp += (long long) TA; TA = 0; } resp += (long long)CT + CA; return resp; } else return -1; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 0; i < a.size(); ++i){
      |                     ~~^~~~~~~~~~
#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...