Language: C++

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
        for (auto &u : v) os << u << el;
        return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
        for (auto &u : v) is >> u;
        return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
        return (is >> p.first >> p.second);
}

int main() {
    ll sx, sy, gx, gy;
    bool flipx, flipy;
    int N;
    cin >> sx >> sy >> gx >> gy;
    cin >> N;
    vector<Pl> data(N+2);
    flipx = sx > gx;
    flipy = sy > gy;

    if (flipx) sx = -sx, gx = -gx;
    if (flipy) sy = -sy, gy = -gy;

    data[0] = make_pair(sx, sy);
    data[N+1] = make_pair(gx, gy);
    for (int i = 1; i <= N; i++) {
        auto &v = data[i];
        cin >> v;
        if (flipx) v.first = -v.first;
        if (flipy) v.second = -v.second;
    }
    sort(begin(data), end(data));
    
    vector<Pl>lis;
    for (int i = 0; i < N+2; i++) {
        auto &v = data[i];
        if (v.first == sx && v.second == sy || 
            v.first == gx && v.second == gy) continue;
        if (v.first < sx || gx < v.first) continue;
        if (v.second < sy || gy < v.second) continue;
        auto pos = lower_bound(begin(lis), end(lis), Pl(v.second, -LLINF));
        if (pos == end(lis)) {
            lis.emplace_back(v.second, v.first);
        } else {
            *pos = Pl(v.second, v.first);
        }
    }
    
    
    for (auto &v : lis) swap(v.first, v.second);
    double dist = (double)(gy - sy + gx - sx) * 100;
    if (lis.size() == 0) {
        cout << fixed << setprecision(15) << dist << endl;
        return (0);
    }
    
    bool c1 = (sx == lis.front().first && gx == lis.back().first);
    bool c2 = (sy == lis.front().second && gy == lis.back().second);
    
    bool f = false;
    if (c1) {
        f = true;
        for (auto &v : lis) swap(v.first, v.second);
        sort(begin(lis), end(lis); 
        for (int i = 0; i < lis.size() - 1; i++) {
            if (lis[i+1].first - lis[i].first > 1) f = false;
        }
    }
    if (c2) {
        f = true;
        sort(begin(lis), end(lis); 
        for (int i = 0; i < lis.size() - 1; i++) {
            if (lis[i+1].first - lis[i].first > 1) f = false;
        }
    }

    if (!f) {
        cout << fixed << setprecision(15) << dist - (double)lis.size() * (20 - 5 * M_PI) << endl;
    } else {
        double ans = dist;
        ans -= (double)(lis.size() - 1) * (20 - 5 * M_PI);
        ans += (10 * M_PI - 20);
        cout << fixed << setprecision(15) << ans << endl;
    }
    
        return (0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:97:34: error: expected ')' before ';' token
   97 |         sort(begin(lis), end(lis);
      |             ~                    ^
      |                                  )
a.cc:104:34: error: expected ')' before ';' token
  104 |         sort(begin(lis), end(lis);
      |             ~                    ^
      |                                  )