Submission #623819

#TimeUsernameProblemLanguageResultExecution timeMemory
623819a_aguiloMutating DNA (IOI21_dna)C++17
0 / 100
29 ms5420 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; vector<int> tree; int n; void buildTree (int node, int left, int right, 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] = tree[2*node] + tree[2*node+1]; } int getValue (int node, int left, int right, int x, int y){ if(x > right or y < left) return 0; if(x <= left and y >= right) return tree[node]; int mid = left + (right - left)/2; return getValue(2*node, left, mid, x, y)+getValue(2*node+1, mid+1, right, x, y); } void init(string a, string b) { n = a.size(); int arr[a.size()]; for (int i = 0; i < a.size(); ++i){ if(a[i] == b[i])arr[i] = 0; else arr[i] = 1; } tree = vector<int> (4*a.size(), 0); buildTree(1, 0, a.size()-1, arr); } int get_distance(int x, int y) { int n = getValue(1, 0, n-1, x, y); if(n%2 != 0) return -1; else return n/2; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < a.size(); ++i){
      |                     ~~^~~~~~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:40:18: warning: 'n' is used uninitialized in this function [-Wuninitialized]
   40 |  int n = getValue(1, 0, n-1, x, y);
      |          ~~~~~~~~^~~~~~~~~~~~~~~~~
#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...