Submission #744132

# Submission time Handle Problem Language Result Execution time Memory
744132 2023-05-18T08:28:27 Z maomao90 Izvanzemaljci (COI21_izvanzemaljci) C++17
100 / 100
1476 ms 9888 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define int ll

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 100005;

int n, k;
ii xy[MAXN];

namespace st1 {
    int main() {
        int mnx = INF, mxx = -INF, mny = INF, mxy = -INF;
        REP (i, 0, n) {
            mnto(mnx, xy[i].FI);
            mxto(mxx, xy[i].FI);
            mnto(mny, xy[i].SE);
            mxto(mxy, xy[i].SE);
        }
        cout << mnx << ' ' << mny << ' ' << max({mxx - mnx, mxy - mny, 1ll}) << '\n';
        return 0;
    }
}
namespace st2 {
    int pmnx[MAXN], pmxx[MAXN], pmny[MAXN], pmxy[MAXN];
    int smnx[MAXN], smxx[MAXN], smny[MAXN], smxy[MAXN];
    iii ans[2];
    int main() {
        int cost = 2 * INF;
        sort(xy, xy + n);
        pmnx[0] = INF, pmxx[0] = -INF, pmny[0] = INF, pmxy[0] = -INF;
        REP (i, 0, n) {
            mnto(pmnx[i], xy[i].FI);
            mxto(pmxx[i], xy[i].FI);
            mnto(pmny[i], xy[i].SE);
            mxto(pmxy[i], xy[i].SE);
            pmnx[i + 1] = pmnx[i];
            pmxx[i + 1] = pmxx[i];
            pmny[i + 1] = pmny[i];
            pmxy[i + 1] = pmxy[i];
        }
        smnx[n] = INF, smxx[n] = -INF, smny[n] = INF, smxy[n] = -INF;
        RREP (i, n - 1, 0) {
            smnx[i] = smnx[i + 1];
            smxx[i] = smxx[i + 1];
            smny[i] = smny[i + 1];
            smxy[i] = smxy[i + 1];
            mnto(smnx[i], xy[i].FI);
            mxto(smxx[i], xy[i].FI);
            mnto(smny[i], xy[i].SE);
            mxto(smxy[i], xy[i].SE);
        }
        REP (i, 0, n) {
            if (i + 1 != n && xy[i].FI == xy[i + 1].FI) {
                continue;
            }
            int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1ll}),
                rht = max({smxx[i + 1] - smnx[i + 1], smxy[i + 1] - smny[i + 1], 1ll});
            if (i + 1 == n) {
                rht = 1;
            }
            if (mnto(cost, max(lft, rht))) {
                ans[0] = {pmxx[i] - lft, pmny[i], lft};
                ans[1] = {smnx[i + 1], smny[i + 1], rht};
                if (i + 1 == n) {
                    ans[1] = {3e9, 3e9, 1};
                }
            }
        }
        sort(xy, xy + n, [&] (ii l, ii r) {
                return l.SE < r.SE;
                });
        pmnx[0] = INF, pmxx[0] = -INF, pmny[0] = INF, pmxy[0] = -INF;
        REP (i, 0, n) {
            mnto(pmnx[i], xy[i].FI);
            mxto(pmxx[i], xy[i].FI);
            mnto(pmny[i], xy[i].SE);
            mxto(pmxy[i], xy[i].SE);
            pmnx[i + 1] = pmnx[i];
            pmxx[i + 1] = pmxx[i];
            pmny[i + 1] = pmny[i];
            pmxy[i + 1] = pmxy[i];
        }
        smnx[n] = INF, smxx[n] = -INF, smny[n] = INF, smxy[n] = -INF;
        RREP (i, n - 1, 0) {
            smnx[i] = smnx[i + 1];
            smxx[i] = smxx[i + 1];
            smny[i] = smny[i + 1];
            smxy[i] = smxy[i + 1];
            mnto(smnx[i], xy[i].FI);
            mxto(smxx[i], xy[i].FI);
            mnto(smny[i], xy[i].SE);
            mxto(smxy[i], xy[i].SE);
        }
        REP (i, 0, n) {
            if (i + 1 == n || xy[i].SE == xy[i + 1].SE) {
                continue;
            }
            int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1ll}),
                rht = max({smxx[i + 1] - smnx[i + 1], smxy[i + 1] - smny[i + 1], 1ll});
            if (i + 1 == n) {
                rht = 1;
            }
            if (mnto(cost, max(lft, rht))) {
                ans[0] = {pmnx[i], pmxy[i] - lft, lft};
                ans[1] = {smnx[i + 1], smny[i + 1], rht};
                if (i + 1 == n) {
                    ans[1] = {3e9, 3e9, 1};
                }
            }
        }
        REP (z, 0, 2) {
            auto [a, b, c] = ans[z];
            cout << a << ' ' << b << ' ' << c << '\n';
        }
        return 0;
    }
}
namespace st5 {
    int cost;
    iii ans[3];
    int pmnx[MAXN], pmxx[MAXN], pmny[MAXN], pmxy[MAXN];
    int smnx[MAXN], smxx[MAXN], smny[MAXN], smxy[MAXN];
    void precomp(int s = 0, int e = n) {
        pmnx[s] = INF, pmxx[s] = -INF, pmny[s] = INF, pmxy[s] = -INF;
        REP (i, s, e) {
            mnto(pmnx[i], xy[i].FI);
            mxto(pmxx[i], xy[i].FI);
            mnto(pmny[i], xy[i].SE);
            mxto(pmxy[i], xy[i].SE);
            pmnx[i + 1] = pmnx[i];
            pmxx[i + 1] = pmxx[i];
            pmny[i + 1] = pmny[i];
            pmxy[i + 1] = pmxy[i];
        }
        smnx[e] = INF, smxx[e] = -INF, smny[e] = INF, smxy[e] = -INF;
        RREP (i, e - 1, s) {
            smnx[i] = smnx[i + 1];
            smxx[i] = smxx[i + 1];
            smny[i] = smny[i + 1];
            smxy[i] = smxy[i + 1];
            mnto(smnx[i], xy[i].FI);
            mxto(smxx[i], xy[i].FI);
            mnto(smny[i], xy[i].SE);
            mxto(smxy[i], xy[i].SE);
        }
    }
    void solve(int v) {
        { // 2 vertical partitions
            sort(xy, xy + n);
            precomp();
            int gd = -1;
            int stop = -3e9;
            ans[0] = {-3e9, -3e9, 1};
            REP (i, 0, n) {
                if (i + 1 != n && xy[i].SE == xy[i + 1].SE) {
                    continue;
                }
                int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1ll});
                if (lft <= v) {
                    ans[0] = {pmxx[i] - lft, pmny[i], lft};
                    gd = i;
                    stop = pmxx[i];
                }
            }
            if (gd == n - 1) {
                cost = v;
                ans[1] = {-3e9, -3e9, 1};
                ans[2] = {3e9, 3e9, 1};
                return;
            }
            precomp(gd + 1, n);
            int tcost = 2 * INF;
            REP (i, gd + 1, n) {
                if (i + 1 != n && xy[i].FI == xy[i + 1].FI) {
                    continue;
                }
                int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1ll}),
                    rht = max({smxx[i + 1] - smnx[i + 1], smxy[i + 1] - smny[i + 1], 1ll});
                if (i + 1 == n) {
                    rht = 1;
                } else if (stop + 1 + lft >= smnx[i + 1]) {
                    continue;
                }
                if (mnto(tcost, max(lft, rht))) {
                    ans[1] = {max(pmxx[i] - lft, stop + 1), pmny[i], lft};
                    ans[2] = {smnx[i + 1], smny[i + 1], rht};
                    if (i + 1 == n) {
                        ans[2] = {3e9, 3e9, 1};
                    }
                }
            }
            if (tcost <= v) {
                cost = v;
                return;
            }
        }
        { // 1 vertical partition followed by 1 horizontal partition
            sort(xy, xy + n);
            precomp();
            int gd = -1;
            ans[0] = {-3e9, -3e9, 1};
            REP (i, 0, n) {
                if (i + 1 != n && xy[i].SE == xy[i + 1].SE) {
                    continue;
                }
                int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1ll});
                if (lft <= v) {
                    ans[0] = {pmxx[i] - lft, pmny[i], lft};
                    gd = i;
                }
            }
            if (gd == n - 1) {
                cost = v;
                ans[1] = {-3e9, -3e9, 1};
                ans[2] = {3e9, 3e9, 1};
                return;
            }
            sort(xy + gd + 1, xy + n, [&] (ii l, ii r) {
                    return l.SE < r.SE;
                    });
            precomp(gd + 1, n);
            int tcost = 2 * INF;
            REP (i, gd + 1, n) {
                if (i + 1 == n || xy[i].SE == xy[i + 1].SE) {
                    continue;
                }
                int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1ll}),
                    rht = max({smxx[i + 1] - smnx[i + 1], smxy[i + 1] - smny[i + 1], 1ll});
                if (i + 1 == n) {
                    rht = 1;
                }
                if (mnto(tcost, max(lft, rht))) {
                    ans[1] = {pmnx[i], pmxy[i] - lft, lft};
                    ans[2] = {smnx[i + 1], smny[i + 1], rht};
                    if (i + 1 == n) {
                        ans[2] = {3e9, 3e9, 1};
                    }
                }
            }
            if (tcost <= v) {
                cost = v;
                return;
            }
        }
    }
    int check(int v) {
        cost = 2 * INF;
        REP (z, 0, 4) {
            if (cost > v) {
                solve(v);
            }
            REP (i, 0, n) {
                int nx = -xy[i].SE, ny = xy[i].FI;
                xy[i] = {nx, ny};
            }
            REP (i, 0, 3) {
                auto [x, y, l] = ans[i];
                int nx = -y - l, ny = x;
                ans[i] = {nx, ny, l};

            }
        }
        return cost <= v;
    }
    int main() {
        int lo = 1, hi = 2 * INF;
        while (lo < hi) {
            int mid = lo + hi >> 1;
            cerr << lo << ' ' << hi << ' ' << mid << '\n';
            if (check(mid)) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        check(hi);
        REP (z, 0, 3) {
            auto [a, b, c] = ans[z];
            cout << a << ' ' << b << ' ' << c << '\n';
        }
        return 0;
    }
}

main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> k;
    REP (i, 0, n) {
        cin >> xy[i].FI >> xy[i].SE;
    }
    if (k == 1) {
        return st1::main();
    } else if (k == 2) {
        return st2::main();
    } else {
        return st5::main();
    }
}

Compilation message

izvanzemaljci.cpp: In function 'll st5::main()':
izvanzemaljci.cpp:301:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  301 |             int mid = lo + hi >> 1;
      |                       ~~~^~~~
izvanzemaljci.cpp: At global scope:
izvanzemaljci.cpp:318:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  318 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 21 ms 1884 KB Output is correct
8 Correct 22 ms 1876 KB Output is correct
9 Correct 27 ms 1848 KB Output is correct
10 Correct 20 ms 1784 KB Output is correct
11 Correct 22 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 39 ms 8012 KB Output is correct
11 Correct 41 ms 8140 KB Output is correct
12 Correct 42 ms 8132 KB Output is correct
13 Correct 42 ms 8020 KB Output is correct
14 Correct 40 ms 8036 KB Output is correct
15 Correct 41 ms 8132 KB Output is correct
16 Correct 39 ms 8012 KB Output is correct
17 Correct 44 ms 7380 KB Output is correct
18 Correct 39 ms 7208 KB Output is correct
19 Correct 32 ms 6612 KB Output is correct
20 Correct 32 ms 7072 KB Output is correct
21 Correct 41 ms 8036 KB Output is correct
22 Correct 41 ms 8124 KB Output is correct
23 Correct 40 ms 8016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 340 KB Output is correct
2 Correct 11 ms 476 KB Output is correct
3 Correct 11 ms 468 KB Output is correct
4 Correct 14 ms 468 KB Output is correct
5 Correct 11 ms 480 KB Output is correct
6 Correct 10 ms 468 KB Output is correct
7 Correct 12 ms 468 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 10 ms 468 KB Output is correct
10 Correct 9 ms 468 KB Output is correct
11 Correct 14 ms 468 KB Output is correct
12 Correct 15 ms 476 KB Output is correct
13 Correct 11 ms 472 KB Output is correct
14 Correct 11 ms 468 KB Output is correct
15 Correct 10 ms 464 KB Output is correct
16 Correct 9 ms 468 KB Output is correct
17 Correct 7 ms 468 KB Output is correct
18 Correct 7 ms 468 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 6 ms 468 KB Output is correct
21 Correct 7 ms 468 KB Output is correct
22 Correct 6 ms 468 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 8 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 11 ms 356 KB Output is correct
3 Correct 12 ms 476 KB Output is correct
4 Correct 10 ms 468 KB Output is correct
5 Correct 16 ms 468 KB Output is correct
6 Correct 12 ms 476 KB Output is correct
7 Correct 15 ms 468 KB Output is correct
8 Correct 15 ms 368 KB Output is correct
9 Correct 15 ms 472 KB Output is correct
10 Correct 12 ms 468 KB Output is correct
11 Correct 10 ms 356 KB Output is correct
12 Correct 10 ms 468 KB Output is correct
13 Correct 10 ms 476 KB Output is correct
14 Correct 873 ms 8012 KB Output is correct
15 Correct 1462 ms 9032 KB Output is correct
16 Correct 817 ms 9520 KB Output is correct
17 Correct 1458 ms 8968 KB Output is correct
18 Correct 847 ms 8868 KB Output is correct
19 Correct 957 ms 9328 KB Output is correct
20 Correct 1476 ms 9888 KB Output is correct
21 Correct 957 ms 7920 KB Output is correct
22 Correct 711 ms 8584 KB Output is correct
23 Correct 578 ms 9164 KB Output is correct
24 Correct 617 ms 9316 KB Output is correct
25 Correct 808 ms 9072 KB Output is correct
26 Correct 1018 ms 9040 KB Output is correct