#include <bits/stdc++.h>
using namespace std;
#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;
vector<int> find_one_square(vector<ii> v){
int minx=INF,maxx=-INF,miny=INF,maxy=-INF;
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(maxx-minx,maxy-miny);
return {minx,miny,l};
}
int main(){
scanf("%d%d",&n,&k);
int x,y;
for(int i=0;i<n;i++){
scanf("%d%d",&x,&y);
all.pb(x,y);
}
if(k==1){
vector<int> ans=find_one_square(all);
if(ans[2]==0)ans[2]=1;
printf("%d %d %d\n",ans[0],ans[1],ans[2]);
}else if(k==2){
int minx=INF,maxx=-INF,miny=INF,maxy=-INF;
for(ii i:all){
minx=min(minx,i.fi);
maxx=max(maxx,i.fi);
miny=min(miny,i.se);
maxy=max(maxy,i.se);
}
int le=1,ri=2*INF;
while(le<ri){
int mi=(le+ri)/2;
vector<ii> v1,v2;
for(ii i:all){
// if this guy is not in the bottom left, add to v1
if(i.fi>minx+mi||i.se>miny+mi){
v1.pb(i);
}
// if not in the top left, add to v2
if(i.fi>minx+mi||i.se<maxy-mi){
v2.pb(i);
}
}
vector<int> res1=find_one_square(v1);
vector<int> res2=find_one_square(v2);
if(res1[2]<=mi||res2[2]<=mi){
ri=mi;
}else{
le=mi+1;
}
}
vector<ii> v1,v2;
for(ii i:all){
// if this guy is not in the bottom left, add to v1
if(i.fi>minx+le||i.se>miny+le){
v1.pb(i);
}
// if not in the top left, add to v2
if(i.fi>minx+le||i.se<maxy-le){
v2.pb(i);
}
}
vector<int> res1=find_one_square(v1);
vector<int> res2=find_one_square(v2);
if(res1[2]<=le){
if(res1[2]==0)res1[2]=1;
printf("%d %d %d\n",res1[0],res1[1],res1[2]);
printf("%d %d %d\n",minx,miny,le);
}else{
if(res2[2]==0)res2[2]=1;
printf("%d %d %d\n",res2[0],res2[1],res2[2]);
printf("%d %d %d\n",minx,maxy-le,le);
}
}else{
}
}
Compilation message
izvanzemaljci.cpp: In function 'int main()':
izvanzemaljci.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
izvanzemaljci.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
# |
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 |
1 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 |
27 ms |
1924 KB |
Output is correct |
8 |
Correct |
40 ms |
1984 KB |
Output is correct |
9 |
Correct |
28 ms |
1968 KB |
Output is correct |
10 |
Correct |
25 ms |
1984 KB |
Output is correct |
11 |
Correct |
26 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Integer -2024691356 violates the range [1, 2*10^9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |