Submission #705561

#TimeUsernameProblemLanguageResultExecution timeMemory
705561jakobrsMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>

struct Count {
  int at, ca, tc;
  int qw;

  Count() : at(0), ca(0), tc(0), qw(0) {}

  inline Count operator-(Count rhs) const {
    Count result = *this;
    result.at -= rhs.at;
    result.ca -= rhs.ca;
    result.tc -= rhs.tc;
    result.qw -= rhs.qw;
    return result;
  }
};

std::vector<Count> prefixes;

void init(std::string_view a, std::string_view b) {
  prefixes.reserve(a.size() + 1);
  Count count;
  prefixes.push_back(count);
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 'A' && b[i] == 'T') count.at += 1;
    if (a[i] == 'T' && b[i] == 'A') count.at -= 1;
    if (a[i] == 'C' && b[i] == 'A') count.ca += 1;
    if (a[i] == 'A' && b[i] == 'C') count.ca -= 1;
    if (a[i] == 'T' && b[i] == 'C') count.tc += 1;
    if (a[i] == 'C' && b[i] == 'T') count.tc -= 1;
    if (a[i] != b[i]) count.qw += 1;
    prefixes.push_back(count);
  }
}

int get_distance(int x, int y) {
  y += 1;

  Count count = prefixes[y] - prefixes[x];

  if (!(count.at == count.ca && count.ca == count.tc)) return -1;

  return (count.qw + std::abs(count.at)) / 2;
}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string_view, std::string_view)':
dna.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::basic_string_view<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for (int i = 0; i < a.size(); i++) {
      |                   ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccJnaTQo.o: in function `main':
grader.cpp:(.text.startup+0x366): undefined reference to `init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status