// 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 - 1) {
if (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 (mnto(cost, max(lft, rht))) {
ans[0] = {pmnx[i], pmxy[i] - lft, lft};
ans[1] = {smnx[i + 1], smny[i + 1], rht};
}
}
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];
}
}
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;
}
}
precomp(gd + 1, n);
int tcost = 2 * INF;
REP (i, gd + 1, n - 1) {
if (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 (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 (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 >> 1;
if (check(mid)) {
lo = mid;
} else {
hi = mid - 1;
}
}
check(lo);
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:279:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
279 | int mid = lo + hi + 1 >> 1;
| ~~~~~~~~^~~
izvanzemaljci.cpp: At global scope:
izvanzemaljci.cpp:295:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
295 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
22 ms |
2060 KB |
Output is correct |
8 |
Correct |
20 ms |
2052 KB |
Output is correct |
9 |
Correct |
22 ms |
2124 KB |
Output is correct |
10 |
Correct |
22 ms |
2040 KB |
Output is correct |
11 |
Correct |
22 ms |
2232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 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 |
42 ms |
9716 KB |
Output is correct |
11 |
Correct |
41 ms |
8972 KB |
Output is correct |
12 |
Correct |
44 ms |
9064 KB |
Output is correct |
13 |
Correct |
46 ms |
8972 KB |
Output is correct |
14 |
Correct |
44 ms |
8992 KB |
Output is correct |
15 |
Correct |
41 ms |
9088 KB |
Output is correct |
16 |
Correct |
45 ms |
8960 KB |
Output is correct |
17 |
Correct |
39 ms |
8264 KB |
Output is correct |
18 |
Correct |
37 ms |
8028 KB |
Output is correct |
19 |
Correct |
33 ms |
7440 KB |
Output is correct |
20 |
Correct |
37 ms |
7904 KB |
Output is correct |
21 |
Correct |
43 ms |
8920 KB |
Output is correct |
22 |
Correct |
41 ms |
8932 KB |
Output is correct |
23 |
Correct |
40 ms |
8908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Integer 0 violates the range [1, 2*10^9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |