Submission #705505

#TimeUsernameProblemLanguageResultExecution timeMemory
705505jakobrsMutating DNA (IOI21_dna)C++17
100 / 100
37 ms4668 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 a, std::string 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, std::string)':
dna.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   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...