제출 #705487

#제출 시각아이디문제언어결과실행 시간메모리
705487jakobrsMutating DNA (IOI21_dna)C++17
컴파일 에러
0 ms0 KiB
#include <xmmintrin.h>

#include <iostream>
#include <vector>

union Count {
  __m128i simd;
  struct {
    int at, ca, tc;
    int qw;
  };

  inline Count operator-(Count rhs) const {
    return Count{.simd = _mm_sub_epi32(simd, rhs.simd)};
  }
};

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);
  prefixes.push_back(Count{});
  Count count{.at = 0, .ca = 0, .tc = 0, .qw = 0};
  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:27:49: error: too many initializers for 'Count'
   27 |   Count count{.at = 0, .ca = 0, .tc = 0, .qw = 0};
      |                                                 ^
dna.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for (int i = 0; i < A.size(); i++) {
      |                   ~~^~~~~~~~~~