// 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 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, 1}) << '\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 - 1) {
if (xy[i].FI == xy[i + 1].FI) {
continue;
}
int lft = max({pmxx[i] - pmnx[i], pmxy[i] - pmny[i], 1}),
rht = max({smxx[i + 1] - smnx[i + 1], smxy[i + 1] - smny[i + 1], 1});
if (mnto(cost, max(lft, rht))) {
ans[0] = {pmxx[i] - lft, pmny[i], lft};
ans[1] = {smnx[i + 1], smny[i + 1], rht};
}
}
sort(xy, xy + n, [&] (ii l, ii r) {
if (l.SE == r.SE) return l.FI < r.FI;
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], 1}),
rht = max({smxx[i + 1] - smnx[i + 1], smxy[i + 1] - smny[i + 1], 1});
if (mnto(cost, max(lft, rht))) {
ans[0] = {pmnx[i], pmxy[i] - lft, lft};
ans[1] = {smnx[i + 1], smny[i + 1], rht};
}
}
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);
}
int l = max({mxx - mnx, mxy - mny, 1});
if (mnto(cost, l)) {
ans[0] = {mnx, mny, l};
ans[1] = {-INF, -INF, 1};
}
REP (z, 0, 2) {
auto [a, b, c] = ans[z];
cout << a << ' ' << b << ' ' << c << '\n';
}
auto [a, b, c] = ans[0];
auto [x, y, z] = ans[1];
assert(a + c < x || x + z < a || b + c < y || y + z < b);
return 0;
}
}
int 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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
268 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
22 ms |
1696 KB |
Output is correct |
8 |
Correct |
23 ms |
1716 KB |
Output is correct |
9 |
Correct |
26 ms |
1636 KB |
Output is correct |
10 |
Correct |
26 ms |
1808 KB |
Output is correct |
11 |
Correct |
25 ms |
1612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |