Problem p01417 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

struct col {
  double L;
  double a;
  double b;
};

double dist(col c1, col c2) {
  double d = (c1.L - c2.L) * (c1.L - c2.L) + (c1.a - c2.a) * (c1.a - c2.a) +
             (c1.b - c2.b) * (c1.b - c2.b);
  return d;
}

void print_bit(unsigned int S, int n = 64) {
  for (int i = n - 1; i >= 0; i--) {
    if (S >> i & 1)
      std::cout << 1;
    else
      std::cout << 0;
  }
  std::cout << std::endl;
}

int main(void) {
  // FILE* fp_in = freopen("data.txt", "r", stdin);
  vector<unsigned int> bits;
  vector<col> cols;
  vector<double> ds;

  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    col c;
    cin >> c.L >> c.a >> c.b;
    cols.push_back(c);
  }

  if (M == 0) {
    printf("%lf\\n", 0.0);
    return 0;
  }

  // ビットテーブル作成
  unsigned long long S = (1ULL << M) - 1ULL;
  unsigned long long E = ~((1ULL << N) - 1ULL);
  while (!(S & E)) {
    bits.push_back(S);
    unsigned long long smallest = S & -S;
    unsigned long long ripple = S + smallest;
    unsigned long long nsmallest = ripple & -ripple;
    S = ripple | (((nsmallest / smallest) >> 1) - 1);
  }

  for (int i = 0; i < bits.size(); i++) {
    double d = 0.0;
    for (int j = 0; j < N; j++) {
      if (!(bits[i] & (1 << j)))
        continue;
      for (int k = j + 1; k < N; k++) {
        if (!(bits[i] & (1 << k)))
          continue;
        d += dist(cols[j], cols[k]);
      }
    }
    ds.push_back(d);
  }

  double max = 0.0;
  for (int i = 0; i < ds.size(); i++)
    if (max < ds[i])
      max = ds[i];

  printf("%.8lf\\n", max);
  // while(1){}
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

struct col {
  double L;
  double a;
  double b;
};

double dist(col c1, col c2) {
  double d = (c1.L - c2.L) * (c1.L - c2.L) + (c1.a - c2.a) * (c1.a - c2.a) +
             (c1.b - c2.b) * (c1.b - c2.b);
  return d;
}

void print_bit(unsigned int S, int n = 64) {
  for (int i = n - 1; i >= 0; i--) {
    if (S >> i & 1)
      std::cout << 1;
    else
      std::cout << 0;
  }
  std::cout << std::endl;
}

int main(void) {
  //	FILE* fp_in = freopen("data.txt", "r", stdin);
  vector<unsigned int> bits;
  vector<col> cols;
  vector<double> ds;

  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    col c;
    cin >> c.L >> c.a >> c.b;
    cols.push_back(c);
  }

  // ビットテーブル作成
  unsigned long long S = (1ULL << M) - 1ULL;
  unsigned long long E = ~((1ULL << N) - 1ULL);
  while (!(S & E)) {
    bits.push_back(S);
    unsigned long long smallest = S & -S;
    unsigned long long ripple = S + smallest;
    unsigned long long nsmallest = ripple & -ripple;
    S = ripple | (((nsmallest / smallest) >> 1) - 1);
  }

  for (int i = 0; i < bits.size(); i++) {
    double d = 0.0;
    for (int j = 0; j < N; j++) {
      if (!(bits[i] & (1 << j)))
        continue;
      for (int k = j + 1; k < N; k++) {
        if (!(bits[i] & (1 << k)))
          continue;
        d += dist(cols[j], cols[k]);
      }
    }
    ds.push_back(d);
  }

  double max = 0.0;
  for (int i = 0; i < ds.size(); i++)
    if (max < ds[i])
      max = ds[i];

  printf("%.8lf\\n", max);
  //	while(1){}
  return 0;
}