Problem p00958 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    os << *it << " ";
  }
  return os;
}

int main(int argc, char *argv[]) {
  int m;
  vector<int> xs, ys;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    xs.push_back(x);
    ys.push_back(y);
  }
  /*
    | x1 y1 1 |
    | x2 y2 1 |
    | x3 y3 1 |
   */
  auto area = [](int x1, int y1, int x2, int y2, int x3, int y3) {
    return x1 * y2 + x2 * y3 + x3 * y1 - (x1 * y3 + x2 * y1 + x3 * y2);
  };
  // 1-2 and 3-4
  auto isPara = [&xs, &ys, &area](int p1, int p2, int p3, int p4) {
    int dx = xs[p1] - xs[p3];
    int dy = ys[p1] - ys[p3];
    return 0 == area(xs[p1], ys[p1], xs[p2], ys[p2], xs[p4] + dx, ys[p4] + dy);
  };
  int memo[256][256];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          memo[(i << 4) + j][(k << 4) + l] = isPara(i, j, k, l) ? 1 : 0;
        }
      }
    }
  }
  vector<bool> vss(m); // choice of sources
  for (int i = 0; i < m / 2; i++) {
    vss[i] = false;
    vss[i + m / 2] = true;
  }
  int mx = 0;
  do {
    // cout << vss << endl;
    vector<int> ts, ss;
    for (int i = 0; i < m; i++) {
      if (!vss[i])
        ts.push_back(i);
      else
        ss.push_back(i);
    }
    do {
      // check if ts[i] > ss[i]
      bool skip = false;
      for (int i = 0; i < m / 2; i++) {
        if (ss[i] < ts[i]) {
          skip = true;
          break;
        }
      }
      if (!skip) {
        int pp = 0;
        for (int i = 0; i < m / 2; i++) {
          const int *mm = memo[(ss[i] << 4) + ts[i]];
          for (int j = i + 1; j < m / 2; j++) {
            pp += mm[(ss[j] << 4) + ts[j]];
          }
        }
        if (pp > mx)
          mx = pp;
      }
    } while (next_permutation(ts.begin(), ts.end()));
  } while (next_permutation(vss.begin(), vss.end()));
  cout << mx << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    os << *it << " ";
  }
  return os;
}

int main(int argc, char *argv[]) {
  int m;
  vector<int> xs, ys;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    xs.push_back(x);
    ys.push_back(y);
  }
  /*
    | x1 y1 1 |
    | x2 y2 1 |
    | x3 y3 1 |
   */
  auto area = [](int x1, int y1, int x2, int y2, int x3, int y3) {
    return x1 * y2 + x2 * y3 + x3 * y1 - (x1 * y3 + x2 * y1 + x3 * y2);
  };
  // 1-2 and 3-4
  auto isPara = [&xs, &ys, &area](int p1, int p2, int p3, int p4) {
    int dx = xs[p1] - xs[p3];
    int dy = ys[p1] - ys[p3];
    return 0 == area(xs[p1], ys[p1], xs[p2], ys[p2], xs[p4] + dx, ys[p4] + dy);
  };
  int memo[256][256];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          memo[(i << 4) + j][(k << 4) + l] = isPara(i, j, k, l) ? 1 : 0;
        }
      }
    }
  }
  vector<bool> vss(m); // choice of sources
  for (int i = 0; i < m / 2; i++) {
    vss[i] = false;
    vss[i + m / 2] = true;
  }
  int mx = 0;
  do {
    // cout << vss << endl;
    vector<int> ts, ss;
    for (int i = 0; i < m; i++) {
      if (!vss[i])
        ts.push_back(i);
      else
        ss.push_back(i);
    }
    do {
      int pp = 0;
      for (int i = 0; i < m / 2; i++) {
        const int *mm = memo[(ss[i] << 4) + ts[i]];
        for (int j = i + 1; j < m / 2; j++) {
          pp += mm[(ss[j] << 4) + ts[j]];
        }
      }
      if (pp > mx)
        mx = pp;
    } while (next_permutation(ts.begin(), ts.end()));
  } while (next_permutation(vss.begin(), vss.end()));
  cout << mx << endl;
  return 0;
}