This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef vector<int> vi;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
int n,k;
vector<ii> all;
map<int,vector<int> > row,col;
vector<int> find_one_square(vector<ii> v){
if(SZ(v)==0)return {0,0,1};
int minx=LLINF,maxx=-LLINF,miny=LLINF,maxy=-LLINF;
for(ii i:v){
minx=min(minx,i.fi);
maxx=max(maxx,i.fi);
miny=min(miny,i.se);
maxy=max(maxy,i.se);
}
int l=max(1LL,max(maxx-minx,maxy-miny));
return {minx,miny,l};
}
bool disjoint(vector<int> v1,vector<int> v2){
return (v1[0]+v1[2]<v2[0])||(v2[0]+v2[2]<v1[0])||(v1[1]+v1[2]<v2[1])||(v2[1]+v2[2]<v1[1]);
}
int32_t main(){
scanf("%lld%lld",&n,&k);
int x,y;
for(int i=0;i<n;i++){
scanf("%lld%lld",&x,&y);
all.pb(x,y);
row[y].pb(x);
col[x].pb(y);
}
if(k==1){
vector<int> ans=find_one_square(all);
printf("%lld %lld %lld\n",ans[0],ans[1],ans[2]);
}else if(k==2){
int le=3*INF;
vector<int> ans[2];
vector<ii> pre,pst;
for(auto it=row.begin();it!=row.end();++it){
sort(ALL(it->se));
pre.clear();pst.clear();
for(ii i:all){
if(i.se<it->fi)pre.pb(i);
if(i.se>it->fi)pst.pb(i);
}
for(int i:it->se){
pst.pb(i,it->fi);
}
for(int i=0;i<SZ(it->se);i++){
vector<int> a1=find_one_square(pre);
vector<int> a2=find_one_square(pst);
if(max(a1[2],a2[2])<le&&disjoint(a1,a2)){
le=max(a1[2],a2[2]);
ans[0]=a1;ans[1]=a2;
}
pre.pb(pst.back());
pst.pop_back();
}
pre.clear();pst.clear();
for(ii i:all){
if(i.se<it->fi)pre.pb(i);
if(i.se>it->fi)pst.pb(i);
}
for(int i=SZ(it->se)-1;i>=0;i--){
pst.pb(i,it->fi);
}
for(int i=0;i<SZ(it->se);i++){
vector<int> a1=find_one_square(pre);
vector<int> a2=find_one_square(pst);
if(max(a1[2],a2[2])<le&&disjoint(a1,a2)){
le=max(a1[2],a2[2]);
ans[0]=a1;ans[1]=a2;
}
pre.pb(pst.back());
pst.pop_back();
}
}
for(auto it=col.begin();it!=col.end();++it){
sort(ALL(it->se));
pre.clear();pst.clear();
for(ii i:all){
if(i.fi<it->fi)pre.pb(i);
if(i.fi>it->fi)pst.pb(i);
}
for(int i:it->se){
pst.pb(i,it->fi);
}
for(int i=0;i<SZ(it->se);i++){
vector<int> a1=find_one_square(pre);
vector<int> a2=find_one_square(pst);
if(max(a1[2],a2[2])<le&&disjoint(a1,a2)){
le=max(a1[2],a2[2]);
ans[0]=a1;ans[1]=a2;
}
pre.pb(pst.back());
pst.pop_back();
}
pre.clear();pst.clear();
for(ii i:all){
if(i.fi<it->fi)pre.pb(i);
if(i.fi>it->fi)pst.pb(i);
}
for(int i=SZ(it->se)-1;i>=0;i--){
pst.pb(i,it->fi);
}
for(int i=0;i<SZ(it->se);i++){
vector<int> a1=find_one_square(pre);
vector<int> a2=find_one_square(pst);
if(max(a1[2],a2[2])<le&&disjoint(a1,a2)){
le=max(a1[2],a2[2]);
ans[0]=a1;ans[1]=a2;
}
pre.pb(pst.back());
pst.pop_back();
}
}
for(int i=0;i<2;i++){for(int j=0;j<3;j++)printf("%lld ",ans[i][j]);printf("\n");}
}else{
}
}
Compilation message (stderr)
izvanzemaljci.cpp: In function 'int32_t main()':
izvanzemaljci.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%lld%lld",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~
izvanzemaljci.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%lld%lld",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |