Problem p03619 (C++)

Buggy submission (status: Runtime Error):
/*
#include <bits/stdc++.h>
#define rf(x)
(x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
inline void myassert(const bool chk, const char *str) {
        if(!chk) {
                puts("0.0");
                fprintf(strerr, "%s", str);
                exit(0);
        }
}

const int MAX_ABS    = 10000;
const int MAX_OP     = 1000;
const int MAX_LINE   = 100;
const int MAX_LEN    = 100;
const int MAX_STRLEN = MAX_LINE * (MAX_LEN + 5) + 55;

struct GPP_SIMULATOR {
        vector<string> V;
        vector<int> S;

        void init() {
                clv(V); clv(S);
        }
};

FILE *in;
char str[MAX_STRLEN];

int main(int argc, char* argv[]) {
        in = fopen(argv[3], "r");
        myassert(in, "Cannot Read The File : CALL YOUN-GYOJUN");
        myassert(0 <= fread(in,
        return 0;
}*/

#include <algorithm>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
#define MAXN 200005
#define pint pair<int, int>
#define f first
#define s second
#define pb push_back
#define sorv(V) sort((V).begin(), (V).end())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

pll wat[MAXN];
ll wn;
const long double pie = acos(0) * 2; // 3.141592653589793238462643383279f;
long double ans;

int main() {
  ll x1, y1, x2, y2, N, x, y, sn, cnt = 0;
  stack<ll> s;

  scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
  if (x1 > x2)
    swap(x1, x2), swap(y1, y2);
  scanf("%lld", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", &x, &y);
    if (x1 <= x && x <= x2 && ((y1 <= y && y <= y2) || (y2 <= y && y <= y1)))
      wat[wn].f = x, wat[wn++].s = y;
  }
  if (x1 == x2 || y1 == y2) {
    vector<long double> tmp;
    for (int t = 0; t < 100; t++)
      tmp.pb(((long double)(x2 - x1 + y2 - y1)));
    if (wn) {
      tmp.pb(((long double)-20));
      tmp.pb((pie * 10.0));
    }
    sorv(tmp);
    for (long double &v : tmp)
      ans += v;
    printf("%.15Lf\n", ans);
    return 0;
  }
  if (y1 > y2) {
    y1 *= -1, y2 *= -1;
    for (int i = 0; i < wn; i++)
      wat[i].s *= -1;
  }

  sort(wat, wat + wn);
  vector<ll> Q;
  for (int i = 0; i < wn; i++) {
    if (!Q.empty() || Q.back() < wat[i].s)
      Q.pb(wat[i].s);
    else {
      const int idx =
          (int)(lower_bound(Q.begin(), Q.end(), wat[i].s) - Q.begin());
      if ((int)Q.size() <= idx)
        Q.pb(wat[i].s);
      else
        Q[idx] = wat[i].s;
    }
  }
  cnt = (int)Q.size();
  // printf("[%d %d %d %d %d]\n", x2, x1, y2, y1, cnt);
  vector<long double> tmp;
  for (int t = 0; t < 100; t++)
    tmp.pb((long double)(x2 - x1 + y2 - y1));
  for (int t = 0; t < cnt; t++)
    tmp.pb((pie * 5 - 20.0));
  if (x2 - x1 + 1 == cnt || y2 - y1 + 1 == cnt) {
    tmp.pb(pie * 5);
  }
  sorv(tmp);
  for (long double &v : tmp)
    ans += v;
  printf("%.15Lf\n", ans);
  return 0;
}

Fixed submission:
/*
#include <bits/stdc++.h>
#define rf(x)
(x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
inline void myassert(const bool chk, const char *str) {
        if(!chk) {
                puts("0.0");
                fprintf(strerr, "%s", str);
                exit(0);
        }
}

const int MAX_ABS    = 10000;
const int MAX_OP     = 1000;
const int MAX_LINE   = 100;
const int MAX_LEN    = 100;
const int MAX_STRLEN = MAX_LINE * (MAX_LEN + 5) + 55;

struct GPP_SIMULATOR {
        vector<string> V;
        vector<int> S;

        void init() {
                clv(V); clv(S);
        }
};

FILE *in;
char str[MAX_STRLEN];

int main(int argc, char* argv[]) {
        in = fopen(argv[3], "r");
        myassert(in, "Cannot Read The File : CALL YOUN-GYOJUN");
        myassert(0 <= fread(in,
        return 0;
}*/

#include <algorithm>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
#define MAXN 200005
#define pint pair<int, int>
#define f first
#define s second
#define pb push_back
#define sorv(V) sort((V).begin(), (V).end())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

pll wat[MAXN];
ll wn;
const long double pie = acos(0) * 2; // 3.141592653589793238462643383279f;
long double ans;

int main() {
  ll x1, y1, x2, y2, N, x, y, sn, cnt = 0;
  stack<ll> s;

  scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
  if (x1 > x2)
    swap(x1, x2), swap(y1, y2);
  scanf("%lld", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", &x, &y);
    if (x1 <= x && x <= x2 && ((y1 <= y && y <= y2) || (y2 <= y && y <= y1)))
      wat[wn].f = x, wat[wn++].s = y;
  }
  if (x1 == x2 || y1 == y2) {
    vector<long double> tmp;
    for (int t = 0; t < 100; t++)
      tmp.pb(((long double)(x2 - x1 + y2 - y1)));
    if (wn) {
      tmp.pb(((long double)-20));
      tmp.pb((pie * 10.0));
    }
    sorv(tmp);
    for (long double &v : tmp)
      ans += v;
    printf("%.15Lf\n", ans);
    return 0;
  }
  if (y1 > y2) {
    y1 *= -1, y2 *= -1;
    for (int i = 0; i < wn; i++)
      wat[i].s *= -1;
  }

  sort(wat, wat + wn);
  vector<ll> Q;
  for (int i = 0; i < wn; i++) {
    if (Q.empty() || Q.back() < wat[i].s)
      Q.pb(wat[i].s);
    else {
      const int idx =
          (int)(lower_bound(Q.begin(), Q.end(), wat[i].s) - Q.begin());
      if ((int)Q.size() <= idx)
        Q.pb(wat[i].s);
      else
        Q[idx] = wat[i].s;
    }
  }
  cnt = (int)Q.size();
  // printf("[%d %d %d %d %d]\n", x2, x1, y2, y1, cnt);
  vector<long double> tmp;
  for (int t = 0; t < 100; t++)
    tmp.pb((long double)(x2 - x1 + y2 - y1));
  for (int t = 0; t < cnt; t++)
    tmp.pb((pie * 5 - 20.0));
  if (x2 - x1 + 1 == cnt || y2 - y1 + 1 == cnt) {
    tmp.pb(pie * 5);
  }
  sorv(tmp);
  for (long double &v : tmp)
    ans += v;
  printf("%.15Lf\n", ans);
  return 0;
}