제출 #705490

#제출 시각아이디문제언어결과실행 시간메모리
705490jakobrsMutating DNA (IOI21_dna)C++17
100 / 100
43 ms4868 KiB
#include <xmmintrin.h>

#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::string a, b;
std::vector<Count> prefixes;

void init(std::string A, std::string B) {
  a = A;
  b = 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;

  int total =
      count.qw - std::abs(count.at) - std::abs(count.tc) - std::abs(count.ca);
  total /= 2;

  return total + std::abs(count.at) * 2;
}

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   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...