이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |