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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A) (A).begin(), (A).end()
#define DUMP(A) cout << #A << "=" << (A) << endl
#define SIZE(A) (int)((A).size())
#define P2(A) ((A) * (A))
using namespace std;
typedef long long ll;

int main() {
  int n;
  for (;;) {
    scanf("%d\\n", &n);
    if (n == 0)
      break;
    vector<double> xs(n), ys(n);
    for (int i = 0; i < n; i++) {
      scanf("%lf,%lf\\n", &xs[i], &ys[i]);
    }
    if (n == 1) {
      printf("1\\n");
      continue;
    }
    int ma = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2,
               vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])),
               llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my)));
        double p1x = mx + (ys[i] - ys[j]) * (llen / vlen),
               p1y = my - (xs[i] - xs[j]) * (llen / vlen);
        double p2x = mx - (ys[i] - ys[j]) * (llen / vlen),
               p2y = my + (xs[i] - xs[j]) * (llen / vlen);
        int now = 0;
        for (int k = 0; k < n; k++) {
          if (sqrt(P2(xs[k] - p1x) + P2(ys[k] - p1y)) <= 1)
            now++;
        }
        ma = max(now, ma);
        now = 0;
        for (int k = 0; k < n; k++) {
          if (sqrt(P2(xs[k] - p2x) + P2(ys[k] - p2y)) <= 1)
            now++;
        }
        ma = max(now, ma);
      }
    }
    printf("%d\\n", ma);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A) (A).begin(), (A).end()
#define DUMP(A) cout << #A << "=" << (A) << endl
#define SIZE(A) (int)((A).size())
#define P2(A) ((A) * (A))
using namespace std;
typedef long long ll;

int main() {
  int n;
  for (;;) {
    scanf("%d\\n", &n);
    if (n == 0)
      break;
    vector<double> xs(n), ys(n);
    for (int i = 0; i < n; i++) {
      scanf("%lf,%lf\\n", &xs[i], &ys[i]);
    }
    if (n == 1) {
      printf("1\\n");
      continue;
    }
    int ma = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2,
               vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])),
               llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my)));
        double p1x = mx + (ys[i] - ys[j]) * (llen / vlen),
               p1y = my - (xs[i] - xs[j]) * (llen / vlen);
        double p2x = mx - (ys[i] - ys[j]) * (llen / vlen),
               p2y = my + (xs[i] - xs[j]) * (llen / vlen);
        int now = 0;
        for (int k = 0; k < n; k++) {
          if (sqrt(P2(xs[k] - p1x) + P2(ys[k] - p1y)) <= 1)
            now++;
        }
        ma = max(now, ma);
        now = 0;
        for (int k = 0; k < n; k++) {
          if (sqrt(P2(xs[k] - p2x) + P2(ys[k] - p2y)) <= 1)
            now++;
        }
        ma = max(now, ma);
      }
    }
    printf("%d\\n", ma);
  }
}