#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 2e9 + 5;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
bool cmp(pair<ll, ll> &a, pair<ll, ll> &b){
return a.second < b.second;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nums, k; cin >> nums >> k;
if (k == 1){
ll mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
for (int i = 0; i < nums; i++){
ll x, y; cin >> x >> y;
mnx = min(mnx, x); mny = min(mny, y);
mxx = max(mxx, x); mxy = max(mxy, y);
}
cout << mnx << ' ' << mny << ' ' << max(1ll, max(mxx - mnx, mxy - mny));
}
else if (k == 2){
vector<iii> ans(2); ll sqsz = inf;
vector<pair<ll, ll>> pts(nums + 1);
pts[0] = {0, 0};
for (int i = 1; i <= nums; i++){
ll x, y; cin >> x >> y;
pts[i] = {x, y};
}
{
sort(pts.begin(), pts.end());
vector<iiii> pref(nums + 1), suff(nums + 2);
ll mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
pref[0] = {mnx, mny, mxx, mxy};
for (int i = 1; i <= nums; i++){
ll x = pts[i].first, y = pts[i].second;
mnx = min(mnx, x); mny = min(mny, y);
mxx = max(mxx, x); mxy = max(mxy, y);
if (i != nums && pts[i].first == pts[i + 1].first) pref[i] = {-inf, -inf, -inf, -inf};
else pref[i] = {mnx, mny, mxx, mxy};
}
mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
suff[nums + 1] = {mnx, mny, mxx, mxy};
for (int i = nums; i >= 1; i--){
ll x = pts[i].first, y = pts[i].second;
mnx = min(mnx, x); mny = min(mny, y);
mxx = max(mxx, x); mxy = max(mxy, y);
if (i != 1 && pts[i].first == pts[i - 1].first) suff[i] = {-inf, -inf, -inf, -inf};
else suff[i] = {mnx, mny, mxx, mxy};
}
for (int i = 0; i <= nums; i++){
if (get<0>(pref[i]) == -inf) continue;
iii psq, ssq; ll sz = 1;
if (i == 0){
psq = {-inf, -inf, 1};
sz = max(sz, 1ll);
}
else{
ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = pref[i];
ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
psq = {cmxx - csz, cmxy - csz, csz};
sz = max(sz, csz);
}
if (i == nums){
ssq = {inf, inf, 1};
sz = max(sz, 1ll);
}
else{
ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = suff[i + 1];
ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
ssq = {cmnx, cmny, csz};
sz = max(sz, csz);
}
if (sz < sqsz){
ans = {psq, ssq};
sqsz = sz;
}
}
}
{
sort(pts.begin(), pts.end(), cmp);
vector<iiii> pref(nums + 1), suff(nums + 2);
ll mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
pref[0] = {mnx, mny, mxx, mxy};
for (int i = 1; i <= nums; i++){
ll x = pts[i].first, y = pts[i].second;
mnx = min(mnx, x); mny = min(mny, y);
mxx = max(mxx, x); mxy = max(mxy, y);
if (i != nums && pts[i].second == pts[i + 1].second) pref[i] = {-inf, -inf, -inf, -inf};
else pref[i] = {mnx, mny, mxx, mxy};
}
mnx = inf, mny = inf, mxx = -inf, mxy = -inf;
suff[nums + 1] = {mnx, mny, mxx, mxy};
for (int i = nums; i >= 1; i--){
ll x = pts[i].first, y = pts[i].second;
mnx = min(mnx, x); mny = min(mny, y);
mxx = max(mxx, x); mxy = max(mxy, y);
if (i != 1 && pts[i].second == pts[i - 1].second) suff[i] = {-inf, -inf, -inf, -inf};
else suff[i] = {mnx, mny, mxx, mxy};
}
for (int i = 0; i <= nums; i++){
if (get<0>(pref[i]) == -inf) continue;
iii psq, ssq; ll sz = 1;
if (i == 0){
psq = {-inf, -inf, 1};
sz = max(sz, 1ll);
}
else{
ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = pref[i];
ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
psq = {cmxx - csz, cmxy - csz, csz};
sz = max(sz, csz);
}
if (i == nums){
ssq = {inf, inf, 1};
sz = max(sz, 1ll);
}
else{
ll cmnx, cmny, cmxx, cmxy; tie(cmnx, cmny, cmxx, cmxy) = suff[i + 1];
ll csz = max(1ll, max(cmxx - cmnx, cmxy - cmny));
ssq = {cmnx, cmny, csz};
sz = max(sz, csz);
}
if (sz < sqsz){
ans = {psq, ssq};
sqsz = sz;
}
}
}
for (int i = 0; i < 2; i++){
ll x, y, sz; tie(x, y, sz) = ans[i];
cout << x << ' ' << y << ' ' << sz << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 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 |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
23 ms |
1532 KB |
Output is correct |
8 |
Correct |
24 ms |
1480 KB |
Output is correct |
9 |
Correct |
22 ms |
1568 KB |
Output is correct |
10 |
Correct |
23 ms |
1584 KB |
Output is correct |
11 |
Correct |
24 ms |
1612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
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 |
332 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |