Submission #998025

# Submission time Handle Problem Language Result Execution time Memory
998025 2024-06-13T08:23:28 Z green_gold_dog Izvanzemaljci (COI21_izvanzemaljci) C++17
26 / 100
2817 ms 12968 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
T square(T a) {
        return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
        ll operator() (pair<ll, ll> p) const {
                return ((__int128)p.first * MOD + p.second) % INF64;
        }
};

ll gmaxpref(map<ll, vector<ll>>& all, ll s) {
        ll nx = all.begin()->first;
        ll miny = INF32, maxy = -INF32;
        auto now = all.begin();
        while (now != all.end()) {
                auto[x, ys] = *now;
                if (x - nx > s) {
                        return x;
                }
                for (auto y : ys) {
                        assign_min(miny, y);
                        assign_max(maxy, y);
                }
                if (maxy - miny > s) {
                        return x;
                }
                now++;
        }
        return INF32;
}

ll gmaxsuff(map<ll, vector<ll>>& all, ll s) {
        ll nx = all.rbegin()->first;
        ll miny = INF32, maxy = -INF32;
        auto now = all.rbegin();
        while (now != all.rend()) {
                auto[x, ys] = *now;
                if (nx - x > s) {
                        return x;
                }
                for (auto y : ys) {
                        assign_min(miny, y);
                        assign_max(maxy, y);
                }
                if (maxy - miny > s) {
                        return x;
                }
                now++;
        }
        return -INF32;
}

pair<bool, vector<tuple<ll, ll, ll>>> s2h(ll s, vector<pair<ll, ll>>& arr, bool b = true) {
        map<ll, vector<ll>> all;
        for (auto[x, y] : arr) {
                all[x].push_back(y);
        }
        ll mpref = gmaxpref(all, s), msuff = gmaxsuff(all, s);
        vector<tuple<ll, ll, ll>> ans;
        if (mpref <= msuff) {
                return make_pair(false, ans);
        }
        ll maxx1 = -INF32, minx1 = INF32;
        ll maxy1 = -INF32, miny1 = INF32;
        ll maxx2 = -INF32, minx2 = INF32;
        ll maxy2 = -INF32, miny2 = INF32;
        for (auto[x, y] : arr) {
                if (x < mpref) {
                        assign_max(maxx1, x);
                        assign_min(minx1, x);
                        assign_max(maxy1, y);
                        assign_min(miny1, y);
                } else {
                        assign_max(maxx2, x);
                        assign_min(minx2, x);
                        assign_max(maxy2, y);
                        assign_min(miny2, y);
                }
        }
        if (b) {
                ans.emplace_back(maxx1 - s, miny1, s);
                ans.emplace_back(minx2, miny2, s);
        } else {
                ans.emplace_back(maxx1 - s, maxy1 - s, s);
                ans.emplace_back(minx2, maxy2 - s, s);
        }
        return make_pair(true, ans);
}

pair<bool, vector<tuple<ll, ll, ll>>> s2v(ll s, vector<pair<ll, ll>>& arr, bool b = true) {
        map<ll, vector<ll>> all;
        for (auto[x, y] : arr) {
                all[y].push_back(x);
        }
        ll mpref = gmaxpref(all, s), msuff = gmaxsuff(all, s);
        vector<tuple<ll, ll, ll>> ans;
        if (mpref <= msuff) {
                return make_pair(false, ans);
        }
        ll maxx1 = -INF32, minx1 = INF32;
        ll maxy1 = -INF32, miny1 = INF32;
        ll maxx2 = -INF32, minx2 = INF32;
        ll maxy2 = -INF32, miny2 = INF32;
        for (auto[x, y] : arr) {
                if (y < mpref) {
                        assign_max(maxx1, x);
                        assign_min(minx1, x);
                        assign_max(maxy1, y);
                        assign_min(miny1, y);
                } else {
                        assign_max(maxx2, x);
                        assign_min(minx2, x);
                        assign_max(maxy2, y);
                        assign_min(miny2, y);
                }
        }
        if (b) {
                ans.emplace_back(minx1, maxy1 - s, s);
                ans.emplace_back(minx2, miny2, s);
        } else {
                ans.emplace_back(maxx1 - s, maxy1 - s, s);
                ans.emplace_back(maxx2 - s, miny2, s);
        }
        return make_pair(true, ans);
}

pair<bool, vector<tuple<ll, ll, ll>>> s3hl(ll s, vector<pair<ll, ll>>& arr) {
        map<ll, vector<ll>> all;
        for (auto[x, y] : arr) {
                all[x].push_back(y);
        }
        ll mpref = gmaxpref(all, s);
        vector<pair<ll, ll>> narr;
        ll maxx = -INF32, minx = INF32;
        ll maxy = -INF32, miny = INF32;
        for (auto[x, y] : arr) {
                if (x < mpref) {
                        assign_max(maxx, x);
                        assign_min(minx, x);
                        assign_max(maxy, y);
                        assign_min(miny, y);
                } else {
                        narr.emplace_back(x, y);
                }
        }
        vector<tuple<ll, ll, ll>> ans;
        ans.emplace_back(maxx - s, maxy - s, s);
        auto[f, nans] = s2v(s, arr, true);
        if (!f) {
                return make_pair(false, nans);
        }
        for (auto i : nans) {
                ans.push_back(i);
        }
        return make_pair(true, ans);
}

pair<bool, vector<tuple<ll, ll, ll>>> s3hr(ll s, vector<pair<ll, ll>>& arr) {
        map<ll, vector<ll>> all;
        for (auto[x, y] : arr) {
                all[x].push_back(y);
        }
        ll msuff = gmaxsuff(all, s);
        vector<pair<ll, ll>> narr;
        ll maxx = -INF32, minx = INF32;
        ll maxy = -INF32, miny = INF32;
        for (auto[x, y] : arr) {
                if (x > msuff) {
                        assign_max(maxx, x);
                        assign_min(minx, x);
                        assign_max(maxy, y);
                        assign_min(miny, y);
                } else {
                        narr.emplace_back(x, y);
                }
        }
        vector<tuple<ll, ll, ll>> ans;
        ans.emplace_back(minx, miny, s);
        auto[f, nans] = s2v(s, arr, false);
        if (!f) {
                return make_pair(false, nans);
        }
        for (auto i : nans) {
                ans.push_back(i);
        }
        return make_pair(true, ans);
}

pair<bool, vector<tuple<ll, ll, ll>>> s3vl(ll s, vector<pair<ll, ll>>& arr) {
        map<ll, vector<ll>> all;
        for (auto[x, y] : arr) {
                all[y].push_back(x);
        }
        ll mpref = gmaxpref(all, s);
        vector<pair<ll, ll>> narr;
        ll maxx = -INF32, minx = INF32;
        ll maxy = -INF32, miny = INF32;
        for (auto[x, y] : arr) {
                if (y < mpref) {
                        assign_max(maxx, x);
                        assign_min(minx, x);
                        assign_max(maxy, y);
                        assign_min(miny, y);
                } else {
                        narr.emplace_back(x, y);
                }
        }
        vector<tuple<ll, ll, ll>> ans;
        ans.emplace_back(maxx - s, maxy - s, s);
        auto[f, nans] = s2h(s, arr, true);
        if (!f) {
                return make_pair(false, nans);
        }
        for (auto i : nans) {
                ans.push_back(i);
        }
        return make_pair(true, ans);
}

pair<bool, vector<tuple<ll, ll, ll>>> s3vr(ll s, vector<pair<ll, ll>>& arr) {
        map<ll, vector<ll>> all;
        for (auto[x, y] : arr) {
                all[y].push_back(x);
        }
        ll msuff = gmaxsuff(all, s);
        vector<pair<ll, ll>> narr;
        ll maxx = -INF32, minx = INF32;
        ll maxy = -INF32, miny = INF32;
        for (auto[x, y] : arr) {
                if (y > msuff) {
                        assign_max(maxx, x);
                        assign_min(minx, x);
                        assign_max(maxy, y);
                        assign_min(miny, y);
                } else {
                        narr.emplace_back(x, y);
                }
        }
        vector<tuple<ll, ll, ll>> ans;
        ans.emplace_back(minx, miny, s);
        auto[f, nans] = s2h(s, arr, false);
        if (!f) {
                return make_pair(false, nans);
        }
        for (auto i : nans) {
                ans.push_back(i);
        }
        return make_pair(true, ans);
}

void solve() {
        ll n, k;
        cin >> n >> k;
        vector<pair<ll, ll>> arr(n);
        for (ll i = 0; i < n; i++) {
                cin >> arr[i].first >> arr[i].second;
        }
        if (k == 1) {
                ll maxx = -INF32, minx = INF32;
                ll maxy = -INF32, miny = INF32;
                for (auto[x, y] : arr) {
                        assign_max(maxx, x);
                        assign_min(minx, x);
                        assign_max(maxy, y);
                        assign_min(miny, y);
                }
                cout << minx << ' ' << miny << ' ' << max(1ll, max(maxx - minx, maxy - miny)) << '\n';
                return;
        }
        if (k == 2) {
                ll l = 0, r = INF32;
                while (r - l > 1) {
                        ll mid = (l + r) / 2;
                        if (s2h(mid, arr).first || s2v(mid, arr).first) {
                                r = mid;
                        } else {
                                l = mid;
                        }
                }
                if (s2h(r, arr).first) {
                        for (auto[a, b, c] : s2h(r, arr).second) {
                                cout << a << ' ' << b << ' ' << c << '\n';
                        }
                } else {
                        for (auto[a, b, c] : s2v(r, arr).second) {
                                cout << a << ' ' << b << ' ' << c << '\n';
                        }
                }
                return;
        }
}

int main() {
        if (IS_FILE) {
                freopen("", "r", stdin);
                freopen("", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t = 1;
        if (IS_TEST_CASES) {
                cin >> t;
        }
        for (ll i = 0; i < t; i++) {
                solve();
        }
}

Compilation message

izvanzemaljci.cpp: In function 'int main()':
izvanzemaljci.cpp:334:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  334 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
izvanzemaljci.cpp:335:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  335 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 15 ms 1884 KB Output is correct
8 Correct 14 ms 1880 KB Output is correct
9 Correct 15 ms 1884 KB Output is correct
10 Correct 16 ms 1884 KB Output is correct
11 Correct 20 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2541 ms 12856 KB Output is correct
11 Correct 2320 ms 12880 KB Output is correct
12 Correct 2470 ms 12880 KB Output is correct
13 Correct 2266 ms 12888 KB Output is correct
14 Correct 2817 ms 12884 KB Output is correct
15 Correct 2321 ms 12968 KB Output is correct
16 Correct 2024 ms 12884 KB Output is correct
17 Correct 1995 ms 11856 KB Output is correct
18 Correct 2001 ms 11348 KB Output is correct
19 Correct 1455 ms 10324 KB Output is correct
20 Correct 1622 ms 11212 KB Output is correct
21 Correct 2535 ms 12884 KB Output is correct
22 Correct 2368 ms 12884 KB Output is correct
23 Correct 1912 ms 12864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -