Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using i32 = int32_t;
- using ui32 = uint32_t;
- using i64 = int64_t;
- using ui64 = uint64_t;
- using namespace std;
- i32 main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- vector<pair<int,int>> arr(n);
- int mnx = 1e6;
- int mny = 1e6;
- int mxx = -1e6;
- int mxy = -1e6;
- for (int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- arr[i] = {x, y};
- mnx = min(mnx, x - 1);
- mny = min(mny, y - 1);
- mxx = max(mxx, x + 1);
- mxy = max(mxy, y + 1);
- }
- pair<int,int> A = {mnx, mny},
- B = {mnx, mxy},
- C = {mxx, mxy},
- D = {mxx, mxy};
- double answer = (mxx - mnx) * 2 + (mxy - mny) * 2;
- {
- int k = 1e7;
- for (int i = 0; i < n; i++) {
- int x = arr[i].first;
- int y = arr[i].second;
- x -= A.first;
- y -= A.second;
- k = min(k, x + y - 1);
- }
- answer -= k * 2;
- answer += k * sqrt(2);
- }
- {
- for (int i = 0; i < n; i++) {
- arr[i].second = mxy - arr[i].second;
- }
- B.second = mxy - B.second;
- int k = 1e7;
- for (int i = 0; i < n; i++) {
- int x = arr[i].first;
- int y = arr[i].second;
- x -= B.first;
- y -= B.second;
- k = min(k, x + y - 1);
- }
- answer -= k * 2;
- answer += k * sqrt(2);
- for (int i = 0; i < n; i++) {
- arr[i].second = mxy - arr[i].second;
- }
- }
- {
- for (int i = 0; i < n; i++) {
- arr[i].second = mxy - arr[i].second;
- arr[i].first = mxx - arr[i].first;
- }
- C.first = 0;
- C.second = 0;
- int k = 1e7;
- for (int i = 0; i < n; i++) {
- int x = arr[i].first;
- int y = arr[i].second;
- x -= B.first;
- y -= B.second;
- k = min(k, x + y - 1);
- }
- answer -= k * 2;
- answer += k * sqrt(2);
- for (int i = 0; i < n; i++) {
- arr[i].second = mxy - arr[i].second;
- arr[i].first = mxx - arr[i].first;
- }
- }
- {
- for (int i = 0; i < n; i++) {
- arr[i].first = mxx - arr[i].first;
- }
- D.first = 0;
- int k = 1e7;
- for (int i = 0; i < n; i++) {
- int x = arr[i].first;
- int y = arr[i].second;
- x -= B.first;
- y -= B.second;
- k = min(k, x + y - 1);
- }
- answer -= k * 2;
- answer += k * sqrt(2);
- for (int i = 0; i < n; i++) {
- arr[i].first = mxx - arr[i].first;
- }
- }
- cout << fixed << setprecision(15) << answer << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement