Problem p03428 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#ifdef _DEBUG_
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

const double EPS = 1e-10;
const double PI = acos(-1.0);

struct PT {
  ll x, y;
  int id;
  PT() {}
  PT(ll x_, ll y_) : x(x_), y(y_), id(-1) {}
  ll len2() const { return x * x + y * y; }
  double len() const { return sqrt(len2()); }
  PT operator-(const PT &b) const { return PT(x - b.x, y - b.y); }
  ll operator*(const PT &b) const { return x * b.x + y * b.y; }
  ll operator%(const PT &b) const { return x * b.y - y * b.x; }
  bool operator<(const PT &b) const { return tie(x, y) < tie(b.x, b.y); }
};

const int MAXN = 123;
PT in[MAXN];
double ans[MAXN];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in[i].x = x;
    in[i].y = y;
    in[i].id = i;
  }
  sort(in, in + N);
  vector<PT> st;
  for (int i = 0; i < N; i++) {
    while (SZ(st) >= 2 &&
           (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = N - 2; i >= 0; i--) {
    while (SZ(st) >= 2 &&
           (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = 0; i < N; i++)
    ans[i] = 0;
  st.PB(st[1]);
  for (int i = 1; i < SZ(st) - 1; i++) {
    PT A = st[i - 1] - st[i];
    PT B = st[i + 1] - st[i];
    double tmp = A * B / (A.len() * B.len());
    // double ang = PI - acos(clamp(tmp, -1.0, 1.0)); // C++ 17 required
    double ang = PI - acos(min(max(tmp, -1.0), 1.0));
    ans[st[i].id] = ang / (2 * PI);
  }
  for (int i = 0; i < N; i++)
    printf("%.10f\n", ans[i]);
  double sum = 0;
  for (int i = 0; i < N; i++)
    sum += ans[i];
  assert(fabs(sum - 1.0) < EPS);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#ifdef _DEBUG_
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

const double EPS = 1e-10;
const double PI = acos(-1.0);

struct PT {
  ll x, y;
  int id;
  PT() {}
  PT(ll x_, ll y_) : x(x_), y(y_), id(-1) {}
  ll len2() const { return x * x + y * y; }
  double len() const { return sqrt(len2()); }
  PT operator-(const PT &b) const { return PT(x - b.x, y - b.y); }
  ll operator*(const PT &b) const { return x * b.x + y * b.y; }
  ll operator%(const PT &b) const { return x * b.y - y * b.x; }
  bool operator<(const PT &b) const { return tie(x, y) < tie(b.x, b.y); }
};

const int MAXN = 123;
PT in[MAXN];
double ans[MAXN];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in[i].x = x;
    in[i].y = y;
    in[i].id = i;
  }
  sort(in, in + N);
  vector<PT> st;
  for (int i = 0; i < N; i++) {
    while (SZ(st) >= 2 &&
           (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = N - 2; i >= 0; i--) {
    while (SZ(st) >= 2 &&
           (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = 0; i < N; i++)
    ans[i] = 0;
  st.PB(st[1]);
  for (int i = 1; i < SZ(st) - 1; i++) {
    PT A = st[i - 1] - st[i];
    PT B = st[i + 1] - st[i];
    double tmp = A * B / (A.len() * B.len());
    // double ang = PI - acos(clamp(tmp, -1.0, 1.0)); // C++ 17 required
    double ang = PI - acos(min(max(tmp, -1.0), 1.0));
    ans[st[i].id] = ang / (2 * PI);
  }
  for (int i = 0; i < N; i++)
    printf("%.10f\n", ans[i]);
  double sum = 0;
  for (int i = 0; i < N; i++)
    sum += ans[i];
  // assert(fabs(sum - 1.0) < EPS);
  return 0;
}