답안 #998018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998018 2024-06-13T08:08:23 Z green_gold_dog Izvanzemaljci (COI21_izvanzemaljci) C++17
26 / 100
2616 ms 14232 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) {
        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);
                }
        }
        ans.emplace_back(maxx1 - s, maxy1 - s, s);
        ans.emplace_back(minx2, miny2, s);
        return make_pair(true, ans);
}

pair<bool, vector<tuple<ll, ll, ll>>> s2v(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), 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);
                }
        }
        ans.emplace_back(maxx1 - s, maxy1 - s, s);
        ans.emplace_back(minx2, miny2, s);
        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:200:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  200 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
izvanzemaljci.cpp:201:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  201 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 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 348 KB Output is correct
7 Correct 18 ms 3164 KB Output is correct
8 Correct 16 ms 3276 KB Output is correct
9 Correct 22 ms 3048 KB Output is correct
10 Correct 16 ms 3152 KB Output is correct
11 Correct 16 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 2613 ms 14040 KB Output is correct
11 Correct 2387 ms 14164 KB Output is correct
12 Correct 2616 ms 14164 KB Output is correct
13 Correct 2439 ms 14092 KB Output is correct
14 Correct 2435 ms 14224 KB Output is correct
15 Correct 2383 ms 14168 KB Output is correct
16 Correct 2084 ms 14160 KB Output is correct
17 Correct 2132 ms 13140 KB Output is correct
18 Correct 2070 ms 12628 KB Output is correct
19 Correct 1469 ms 11348 KB Output is correct
20 Correct 1743 ms 12116 KB Output is correct
21 Correct 2591 ms 14232 KB Output is correct
22 Correct 2541 ms 14168 KB Output is correct
23 Correct 1906 ms 14044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -