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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-8;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int n;
int main(void) {
  while (cin >> n) {
    if (n == 0)
      break;
    double x[100], y[100];
    REP(i, n) { scanf("%lf,%lf", x + i, y + i); }
    int ans = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double dist =
            sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]));
        if (dist > 2)
          continue;
        double thete = atan2(y[j] - y[i], x[j] - x[i]);
        double alpha = acos((dist * dist) / (2 * dist));
        double kx[2], ky[2];
        kx[0] = x[i] + cos(thete + alpha);
        ky[0] = y[i] + sin(thete + alpha);
        kx[1] = x[i] + cos(thete - alpha);
        ky[1] = y[i] + sin(thete - alpha);
        int tmp = 2;
        REP(k, n) {
          if (i == k || j == k)
            continue;
          double d = sqrt((x[k] - kx[0]) * (x[k] - kx[0]) +
                          (y[k] - ky[0]) * (y[k] - ky[0]));
          if (d < 1 + EPS)
            tmp++;
        }
        ans = max(tmp, ans);
        tmp = 2;
        REP(k, n) {
          if (i == k || j == k)
            continue;
          double d = sqrt((x[k] - kx[1]) * (x[k] - kx[1]) +
                          (y[k] - ky[1]) * (y[k] - ky[1]));
          if (d < 1 + EPS)
            tmp++;
        }
        ans = max(tmp, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-8;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int n;
int dfs(int searched, vector<int> seal, vector<set<int>> &over) {
  int newseal = -1;
  FOR(i, searched, n) {
    if (find(seal.begin(), seal.end(), i) != seal.end())
      continue;
    bool ok = true;
    REP(j, seal.size()) {
      if (over[seal[j]].find(i) == over[seal[j]].end()) {
        ok = false;
        break;
      }
    }
    if (ok) {
      newseal = i;
      break;
    }
  }
  int ret;
  if (newseal == -1) {
    ret = seal.size();
  } else {
    vector<int> nextseal = seal;
    nextseal.push_back(newseal);
    ret = dfs(0, nextseal, over);
    ret = max(ret, dfs(newseal + 1, seal, over));
  }
  return ret;
}
int main(void) {
  while (cin >> n) {
    if (n == 0)
      break;
    double x[100], y[100];
    double d[100][100];
    vector<set<int>> overlap(n);
    REP(i, n) REP(j, n) d[i][j] = 100.0;
    REP(i, n) { scanf("%lf,%lf", x + i, y + i); }
    REP(i, n) FOR(j, i + 1, n) {
      double dist =
          sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]));
      if (dist < 2 + EPS) {
        overlap[i].insert(j);
        overlap[j].insert(i);
      }
    }
    cout << dfs(0, vector<int>(), overlap) << endl;
  }
  return 0;
}