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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef vector<Int> vInt;
typedef pair<int, int> pint;
typedef pair<Int, Int> pInt;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef vector<pInt> vpInt;
typedef stringstream SS;

template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repn(i, m, n) for (int i = (m); i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repnd(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define rep0(i, n) for (i = 0; i < (n); ++i)
#define repn0(i, m, n) for (i = (m); i < (n); ++i)
#define repd0(i, n) for (i = (n)-1; i >= 0; --i)
#define repnd0(i, m, n) for (i = (n)-1; i >= (m); --i)
#define repc(i, n) for (int i = 0; i <= (n); ++i)
#define repcn(i, m, n) for (int i = (m); i <= (n); ++i)
#define repcd(i, n) for (int i = (n); i >= 0; --i)
#define repcnd(i, m, n) for (int i = (n); i >= (m); --i)
#define repc0(i, n) for (i = 0; i <= (n); ++i)
#define repcn0(i, m, n) for (i = (m); i <= (n); ++i)
#define repcd0(i, n) for (i = (n); i >= 0; --i)
#define repcnd0(i, m, n) for (i = (n); i >= (m); --i)
#define all(n) n.begin(), n.end()
#define sz(n) ((int)(n).size())
#define IL for (;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n, vector<n>, greater<n>>
#define PUTLINE cout << "LINE:" << __LINE__ << endl;

const int INF = 2147483647 / 3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1, 0};

double color[30][3];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> color[i][0] >> color[i][1] >> color[i][2];
  int tmp, low;
  double mx = 0;
  if (m > 1) {
    for (int bit = (1 << m) - 1; bit < (1 << n); low = bit & -bit, tmp = bit,
             bit += low, bit |= (bit ^ tmp) / low >> 2) {
      double sum = 0;
      rep(i, n) if ((bit & 1 << i) > 0)
          repn(j, i + 1, n) if ((bit & 1 << j) > 0) {
        sum += pow(color[i][0] - color[j][0], 2);
        sum += pow(color[i][1] - color[j][1], 2);
        sum += pow(color[i][2] - color[j][2], 2);
      }
      chmax(mx, sum);
    }
  }
  printf("%.12lf\\n", mx);
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef vector<Int> vInt;
typedef pair<int, int> pint;
typedef pair<Int, Int> pInt;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef vector<pInt> vpInt;
typedef stringstream SS;

template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repn(i, m, n) for (int i = (m); i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repnd(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define rep0(i, n) for (i = 0; i < (n); ++i)
#define repn0(i, m, n) for (i = (m); i < (n); ++i)
#define repd0(i, n) for (i = (n)-1; i >= 0; --i)
#define repnd0(i, m, n) for (i = (n)-1; i >= (m); --i)
#define repc(i, n) for (int i = 0; i <= (n); ++i)
#define repcn(i, m, n) for (int i = (m); i <= (n); ++i)
#define repcd(i, n) for (int i = (n); i >= 0; --i)
#define repcnd(i, m, n) for (int i = (n); i >= (m); --i)
#define repc0(i, n) for (i = 0; i <= (n); ++i)
#define repcn0(i, m, n) for (i = (m); i <= (n); ++i)
#define repcd0(i, n) for (i = (n); i >= 0; --i)
#define repcnd0(i, m, n) for (i = (n); i >= (m); --i)
#define all(n) n.begin(), n.end()
#define sz(n) ((int)(n).size())
#define IL for (;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n, vector<n>, greater<n>>
#define PUTLINE cout << "LINE:" << __LINE__ << endl;

const int INF = 2147483647 / 3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1, 0};

double color[30][3];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> color[i][0] >> color[i][1] >> color[i][2];
  int tmp, low;
  double mx = 0;
  for (int bit = (1 << m) - 1; bit < (1 << n);
       low = bit & -bit, tmp = bit, bit += low, bit |= (bit ^ tmp) / low >> 2) {
    double sum = 0;
    rep(i, n) if ((bit & 1 << i) > 0)
        repn(j, i + 1, n) if ((bit & 1 << j) > 0) {
      sum += pow(color[i][0] - color[j][0], 2);
      sum += pow(color[i][1] - color[j][1], 2);
      sum += pow(color[i][2] - color[j][2], 2);
    }
    chmax(mx, sum);
  }
  printf("%.12lf\\n", mx);
  return 0;
}