Submission #744253

# Submission time Handle Problem Language Result Execution time Memory
744253 2023-05-18T10:00:01 Z jamielim Izvanzemaljci (COI21_izvanzemaljci) C++14
26 / 100
42 ms 3552 KB
#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;
int premin[100005];
int premax[100005];
int sufmin[100005];
int sufmax[100005];

vector<ll> find_one_square(vector<ii> v){
	if(SZ(v)==0)return {0,0,1};
	ll minx=LLINF,maxx=-LLINF,miny=LLINF,maxy=-LLINF;
	for(ii i:v){
		minx=min(minx,(ll)i.fi);
		maxx=max(maxx,(ll)i.fi);
		miny=min(miny,(ll)i.se);
		maxy=max(maxy,(ll)i.se);
	}
	ll l=max(1LL,max(maxx-minx,maxy-miny));
	return {minx,miny,l};
}
vector<ll> an[2];
vector<vector<ll> > find_two_squares(vector<ii> v){
	an[0]=find_one_square(v);
	an[1]={2012345678,2012345678,1};
	ll le=an[0][2];
	sort(ALL(v));
	for(int i=0;i<n;i++){
		if(i==0){
			premin[i]=v[i].se;
			premax[i]=v[i].se;
		}else{
			premin[i]=min(premin[i-1],v[i].se);
			premax[i]=max(premax[i-1],v[i].se);
		}
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1){
			sufmin[i]=v[i].se;
			sufmax[i]=v[i].se;
		}else{
			sufmin[i]=min(sufmin[i+1],v[i].se);
			sufmax[i]=max(sufmax[i+1],v[i].se);
		}
	}
	for(int i=0;i<n-1;i++){
		ll hor=max(max(v[i].fi-v[0].fi,v[n-1].fi-v[i+1].fi),1);
		ll ver=max(max(premax[i]-premin[i],sufmax[i+1]-sufmin[i+1]),1);
		ll l=max(hor,ver);
		if(l<le){
			le=l;
			an[0]={v[i].fi-l,premax[i]-l,l};
			an[1]={v[i+1].fi,sufmin[i+1],l};
		}
	}
	
	for(int i=0;i<n;i++)swap(v[i].fi,v[i].se);
	sort(ALL(v));
	for(int i=0;i<n;i++){
		if(i==0){
			premin[i]=v[i].se;
			premax[i]=v[i].se;
		}else{
			premin[i]=min(premin[i-1],v[i].se);
			premax[i]=max(premax[i-1],v[i].se);
		}
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1){
			sufmin[i]=v[i].se;
			sufmax[i]=v[i].se;
		}else{
			sufmin[i]=min(sufmin[i+1],v[i].se);
			sufmax[i]=max(sufmax[i+1],v[i].se);
		}
	}
	for(int i=0;i<n-1;i++){
		ll hor=max(max(v[i].fi-v[0].fi,v[n-1].fi-v[i+1].fi),1);
		ll ver=max(max(premax[i]-premin[i],sufmax[i+1]-sufmin[i+1]),1);
		ll l=max(hor,ver);
		if(l<le){
			le=l;
			an[0]={premax[i]-l,v[i].fi-l,l};
			an[1]={sufmin[i+1],v[i+1].fi,l};
		}
	}
	return {an[0],an[1]};
}

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("%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<ll> ans=find_one_square(all);
		printf("%lld %lld %lld\n",ans[0],ans[1],ans[2]);
	}else if(k==2){
		vector<vector<ll> > ans=find_two_squares(all);
		for(int i=0;i<2;i++){for(int j=0;j<3;j++)printf("%lld ",ans[i][j]);printf("\n");}
	}else{
		vector<vector<ll> > ans=find_two_squares(all);
		vector<ll> tmp={2012345688,2012345688,1};
		ans.pb(tmp);
		if(n<=2){
			for(int i=0;i<3;i++){for(int j=0;j<3;j++)printf("%lld ",ans[i][j]);printf("\n");}
			return 0;
		}
		vector<vector<ll> > a;
		vector<ii> v;
		
		//printf("1\n");
		sort(ALL(all));
		vector<int> disc;
		for(int i=0;i<n;i++){
			if(i==0)disc.pb(i);
			else if(all[i].fi>all[i-1].fi)disc.pb(i);
		}
		int pmin[n],pmax[n];
		for(int i=0;i<n;i++){
			if(i==0){pmin[i]=all[i].se;pmax[i]=all[i].se;}
			else{pmin[i]=min(pmin[i-1],all[i].se);pmax[i]=max(pmax[i-1],all[i].se);}
		}
		int l=1,r=SZ(disc)-1;
		while(l<r){
			//printf("%d %d\n",l,r);
			int m=(l+r+1)/2;
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(all[i]);
			a=find_two_squares(v);
			int L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			if(L>max(a[0][2],a[1][2]))r=m-1;
			else l=m;
		}
		for(int m=l;m<=l+1;m++){
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(all[i]);
			a=find_two_squares(v);
			ll L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			ll maxl=max(L,max(a[0][2],a[1][2]));
			if(maxl<max(max(ans[0][2],ans[1][2]),ans[2][2])){
				ans[0]=a[0];
				ans[1]=a[1];
				ans[2]={all[idx-1].fi-L,pmin[idx-1],L};
			}
		}
		
		//printf("2\n");
		for(int i=0;i<n;i++)all[i].fi=-all[i].fi;
		sort(ALL(all));
		disc.clear();
		for(int i=0;i<n;i++){
			if(i==0)disc.pb(i);
			else if(all[i].fi>all[i-1].fi)disc.pb(i);
		}
		for(int i=0;i<n;i++){
			if(i==0){pmin[i]=all[i].se;pmax[i]=all[i].se;}
			else{pmin[i]=min(pmin[i-1],all[i].se);pmax[i]=max(pmax[i-1],all[i].se);}
		}
		l=1;r=SZ(disc)-1;
		while(l<r){
			int m=(l+r+1)/2;
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(-all[i].fi,all[i].se);
			a=find_two_squares(v);
			int L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			if(L>max(a[0][2],a[1][2]))r=m-1;
			else l=m;
		}
		for(int m=l;m<=l+1;m++){
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(-all[i].fi,all[i].se);
			a=find_two_squares(v);
			ll L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			ll maxl=max(L,max(a[0][2],a[1][2]));
			if(maxl<max(max(ans[0][2],ans[1][2]),ans[2][2])){
				ans[0]=a[0];
				ans[1]=a[1];
				ans[2]={-all[idx-1].fi,pmin[idx-1],L};
			}
		}
		
		//printf("3\n");
		for(int i=0;i<n;i++){all[i].fi=-all[i].fi;swap(all[i].fi,all[i].se);}
		sort(ALL(all));
		disc.clear();
		for(int i=0;i<n;i++){
			if(i==0)disc.pb(i);
			else if(all[i].fi>all[i-1].fi)disc.pb(i);
		}
		for(int i=0;i<n;i++){
			if(i==0){pmin[i]=all[i].se;pmax[i]=all[i].se;}
			else{pmin[i]=min(pmin[i-1],all[i].se);pmax[i]=max(pmax[i-1],all[i].se);}
		}
		l=1,r=SZ(disc)-1;
		while(l<r){
			int m=(l+r+1)/2;
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(all[i].se,all[i].fi);
			a=find_two_squares(v);
			int L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			if(L>max(a[0][2],a[1][2]))r=m-1;
			else l=m;
		}
		for(int m=l;m<=l+1;m++){
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(all[i].se,all[i].fi);
			a=find_two_squares(v);
			ll L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			ll maxl=max(L,max(a[0][2],a[1][2]));
			if(maxl<max(max(ans[0][2],ans[1][2]),ans[2][2])){
				ans[0]=a[0];
				ans[1]=a[1];
				ans[2]={pmin[idx-1],all[idx-1].fi-L,L};
			}
		}
		
		//printf("4\n");
		for(int i=0;i<n;i++)all[i].fi=-all[i].fi;
		sort(ALL(all));
		disc.clear();
		for(int i=0;i<n;i++){
			if(i==0)disc.pb(i);
			else if(all[i].fi>all[i-1].fi)disc.pb(i);
		}
		for(int i=0;i<n;i++){
			if(i==0){pmin[i]=all[i].se;pmax[i]=all[i].se;}
			else{pmin[i]=min(pmin[i-1],all[i].se);pmax[i]=max(pmax[i-1],all[i].se);}
		}
		l=1;r=SZ(disc)-1;
		while(l<r){
			int m=(l+r+1)/2;
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(all[i].se,-all[i].fi);
			a=find_two_squares(v);
			int L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			if(L>max(a[0][2],a[1][2]))r=m-1;
			else l=m;
		}
		for(int m=l;m<=l+1;m++){
			int idx=disc[m];
			v.clear();
			for(int i=idx;i<n;i++)v.pb(all[i].se,-all[i].fi);
			a=find_two_squares(v);
			ll L=max(max(all[idx-1].fi-all[0].fi,pmax[idx-1]-pmin[idx-1]),1);
			ll maxl=max(L,max(a[0][2],a[1][2]));
			if(maxl<max(max(ans[0][2],ans[1][2]),ans[2][2])){
				ans[0]=a[0];
				ans[1]=a[1];
				ans[2]={pmin[idx-1],-all[idx-1].fi,L};
			}
		}
		
		for(int i=0;i<3;i++){for(int j=0;j<3;j++)printf("%lld ",ans[i][j]);printf("\n");}
	}
}
/*
5 2
1 3
3 1
5 5
5 10
7 7

5 3
1 3
3 1
5 5
5 10
7 7
*/

Compilation message

izvanzemaljci.cpp: In function 'int32_t main()':
izvanzemaljci.cpp:112:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
izvanzemaljci.cpp:115:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 23 ms 1960 KB Output is correct
8 Correct 22 ms 1976 KB Output is correct
9 Correct 22 ms 2016 KB Output is correct
10 Correct 21 ms 1908 KB Output is correct
11 Correct 22 ms 2012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 42 ms 3504 KB Output is correct
11 Correct 41 ms 3500 KB Output is correct
12 Correct 41 ms 3504 KB Output is correct
13 Correct 40 ms 3552 KB Output is correct
14 Correct 41 ms 3540 KB Output is correct
15 Correct 40 ms 3504 KB Output is correct
16 Correct 42 ms 3500 KB Output is correct
17 Correct 38 ms 3256 KB Output is correct
18 Correct 35 ms 3184 KB Output is correct
19 Correct 32 ms 2896 KB Output is correct
20 Correct 36 ms 3084 KB Output is correct
21 Correct 41 ms 3540 KB Output is correct
22 Correct 41 ms 3432 KB Output is correct
23 Correct 42 ms 3544 KB Output is correct
# Verdict Execution time Memory 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 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Runtime error 1 ms 432 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 452 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -