답안 #744474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744474 2023-05-18T15:28:14 Z jamielim Izvanzemaljci (COI21_izvanzemaljci) C++14
26 / 100
57 ms 5472 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<ii> one_input;
inline vector<ll> find_one_square(){
	if(SZ(one_input)==0)return {0,0,1};
	ll minx=LLINF,maxx=-LLINF,miny=LLINF,maxy=-LLINF;
	for(ii i:one_input){
		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<ii> two_input;
inline vector<vector<ll> > find_two_squares(){
	one_input=two_input;
	an[0]=find_one_square();
	an[1]={2012345678,2012345678,1};
	ll le=an[0][2];
	sort(ALL(two_input));
	for(int i=0;i<n;i++){
		if(i==0){
			premin[i]=two_input[i].se;
			premax[i]=two_input[i].se;
		}else{
			premin[i]=min(premin[i-1],two_input[i].se);
			premax[i]=max(premax[i-1],two_input[i].se);
		}
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1){
			sufmin[i]=two_input[i].se;
			sufmax[i]=two_input[i].se;
		}else{
			sufmin[i]=min(sufmin[i+1],two_input[i].se);
			sufmax[i]=max(sufmax[i+1],two_input[i].se);
		}
	}
	for(int i=0;i<n-1;i++){
		ll l1=max(max(two_input[i].fi-two_input[0].fi,premax[i]-premin[i]),1);
		ll l2=max(max(sufmax[i+1]-sufmin[i+1],two_input[n-1].fi-two_input[i+1].fi),1);
		ll l=max(l1,l2);
		if(l<le){
			le=l;
			an[0]={two_input[i].fi-l1,premin[i],l1};
			an[1]={two_input[i+1].fi,sufmin[i+1],l2};
		}
	}
	
	for(int i=0;i<n;i++)swap(two_input[i].fi,two_input[i].se);
	sort(ALL(two_input));
	for(int i=0;i<n;i++){
		if(i==0){
			premin[i]=two_input[i].se;
			premax[i]=two_input[i].se;
		}else{
			premin[i]=min(premin[i-1],two_input[i].se);
			premax[i]=max(premax[i-1],two_input[i].se);
		}
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1){
			sufmin[i]=two_input[i].se;
			sufmax[i]=two_input[i].se;
		}else{
			sufmin[i]=min(sufmin[i+1],two_input[i].se);
			sufmax[i]=max(sufmax[i+1],two_input[i].se);
		}
	}
	for(int i=0;i<n-1;i++){
		ll l1=max(max(two_input[i].fi-two_input[0].fi,premax[i]-premin[i]),1);
		ll l2=max(max(sufmax[i+1]-sufmin[i+1],two_input[n-1].fi-two_input[i+1].fi),1);
		ll l=max(l1,l2);
		if(l<le){
			le=l;
			an[0]={premin[i],two_input[i].fi-l1,l1};
			an[1]={sufmin[i+1],two_input[i+1].fi,l2};
		}
	}
	for(int i=0;i<n;i++)swap(two_input[i].fi,two_input[i].se);
	return {an[0],an[1]};
}
inline vector<vector<ll> > find_two_part(){
	// top right and bottom right
	one_input=two_input;
	an[0]=find_one_square();
	an[1]={2012345678,2012345678,1};
	ll le=an[0][2];
	for(int i=0;i<n;i++)swap(two_input[i].fi,two_input[i].se);
	sort(ALL(two_input));
	for(int i=0;i<n;i++){
		if(i==0){
			premin[i]=two_input[i].se;
			premax[i]=two_input[i].se;
		}else{
			premin[i]=min(premin[i-1],two_input[i].se);
			premax[i]=max(premax[i-1],two_input[i].se);
		}
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1){
			sufmin[i]=two_input[i].se;
			sufmax[i]=two_input[i].se;
		}else{
			sufmin[i]=min(sufmin[i+1],two_input[i].se);
			sufmax[i]=max(sufmax[i+1],two_input[i].se);
		}
	}
	for(int i=0;i<n-1;i++){
		ll l1=max(max(two_input[i].fi-two_input[0].fi,premax[i]-premin[i]),1);
		ll l2=max(max(sufmax[i+1]-sufmin[i+1],two_input[n-1].fi-two_input[i+1].fi),1);
		ll l=max(l1,l2);
		if(l<le){
			le=l;
			an[0]={premin[i],two_input[i].fi-l1,l1};
			an[1]={sufmin[i+1],two_input[i+1].fi,l2};
		}
	}

	for(int i=0;i<n;i++)swap(two_input[i].fi,two_input[i].se);
	return {an[0],an[1]};
}
vector<ii> par_input;
inline vector<vector<ll> > parallel(){
	vector<int> disc;
	for(int i=0;i<n;i++){
		if(i==0)disc.pb(i);
		else if(par_input[i].fi>par_input[i-1].fi)disc.pb(i);
	}
	int pmin[n],pmax[n],smin[n],smax[n];
	for(int i=0;i<n;i++){
		if(i==0)pmin[i]=pmax[i]=par_input[i].se;
		else pmin[i]=min(pmin[i-1],par_input[i].se),pmax[i]=max(pmax[i-1],par_input[i].se);
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1)smin[i]=smax[i]=par_input[i].se;
		else smin[i]=min(smin[i+1],par_input[i].se),smax[i]=max(smax[i+1],par_input[i].se);
	}
	ll l=1,r=2*INF;
	while(l<r){
		ll m=(l+r)/2;
		int idx1=-1;
		for(int i=1;i<SZ(disc);i++){
			int cur=disc[i]-1;
			if(max(pmax[cur]-pmin[cur],par_input[cur].fi-par_input[0].fi)<=m){
				idx1=cur;
			}else break;
		}
		
		int idx3=n;
		for(int i=SZ(disc)-1;i>=0;i--){
			int cur=disc[i];
			if(max(smax[cur]-smin[cur],par_input[n-1].fi-par_input[cur].fi)<=m){
				idx3=cur;
			}else break;
		}
		
		int mn=2*INF,mx=-2*INF;
		for(int i=idx1+1;i<=idx3-1;i++){
			mn=min(mn,par_input[i].se);
			mx=max(mx,par_input[i].se);
		}
		if(mn>mx)r=m;
		else if(mx-mn<=par_input[idx3].fi-1-par_input[idx1].fi+1&&
				max(mx-mn,par_input[idx3-1].fi-par_input[idx1+1].fi)<=m)r=m;
		else l=m+1;
	}
	
	int idx1=-1;
	for(int i=1;i<SZ(disc);i++){
		int cur=disc[i]-1;
		if(max(pmax[cur]-pmin[cur],par_input[cur].fi-par_input[0].fi)<=l){
			idx1=cur;
		}else break;
	}
	int l1=max(1,max(pmax[idx1]-pmin[idx1],par_input[idx1].fi-par_input[0].fi));
	int x1=par_input[idx1].fi-l1,y1=pmin[idx1];
	
	int idx3=n;
	for(int i=SZ(disc)-1;i>=0;i--){
		int cur=disc[i];
		if(max(smax[cur]-smin[cur],par_input[n-1].fi-par_input[cur].fi)<=l){
			idx3=cur;
		}else break;
	}
	int l3=max(1,max(smax[idx3]-smin[idx3],par_input[n-1].fi-par_input[idx3].fi));
	int x3=par_input[idx3].fi,y3=smin[idx3];
	
	int mn=2*INF,mx=-2*INF;
	for(int i=idx1+1;i<=idx3-1;i++){
		mn=min(mn,par_input[i].se);
		mx=max(mx,par_input[i].se);
	}
	int l2=max(mx-mn,par_input[idx3-1].fi-par_input[idx1+1].fi);
	int x2=min(par_input[idx3].fi-1-l2,par_input[idx1+1].fi);
	
	return {{x1,y1,l1},{x2,mn,l2},{x3,y3,l3}};
}

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){
		one_input=all;
		vector<ll> ans=find_one_square();
		printf("%lld %lld %lld\n",ans[0],ans[1],ans[2]);
	}else if(k==2){
		two_input=all;
		vector<vector<ll> > ans=find_two_squares();
		for(int i=0;i<2;i++){for(int j=0;j<3;j++)printf("%lld ",ans[i][j]);printf("\n");}
	}else{
		two_input=all;
		vector<vector<ll> > ans=find_two_squares();
		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]);
			two_input=v;
			a=find_two_part();
			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]);
			two_input=v;
			a=find_two_part();
			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};
			}
		}
		
		//1b: parallel
		par_input=all;
		a=parallel();
		if(max(max(a[0][2],a[1][2]),a[2][2])<max(max(ans[0][2],ans[1][2]),ans[2][2])){
			ans[0]=a[0];ans[1]=a[1];ans[2]=a[2];
		}
		
		//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]);
			two_input=v;
			a=find_two_part();
			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]);
			two_input=v;
			a=find_two_part();
			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])){
				a[0][0]=-a[0][0];a[1][0]=-a[1][0];
				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]);
			two_input=v;
			a=find_two_part();
			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]);
			two_input=v;
			a=find_two_part();
			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])){
				swap(a[0][0],a[0][1]);swap(a[1][0],a[1][1]);
				ans[0]=a[0];
				ans[1]=a[1];
				ans[2]={pmin[idx-1],all[idx-1].fi-L,L};
			}
		}
		
		// 3b: parallel
		par_input=all;
		a=parallel();
		if(max(max(a[0][2],a[1][2]),a[2][2])<max(max(ans[0][2],ans[1][2]),ans[2][2])){
			swap(a[0][0],a[0][1]);swap(a[1][0],a[1][1]);swap(a[2][0],a[2][1]);
			ans[0]=a[0];ans[1]=a[1];ans[2]=a[2];
		}
		
		//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]);
			two_input=v;
			a=find_two_part();
			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]);
			two_input=v;
			a=find_two_part();
			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])){
				a[0][0]=-a[0][0];a[1][0]=-a[1][0];
				swap(a[0][0],a[0][1]);swap(a[1][0],a[1][1]);
				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:228:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  228 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
izvanzemaljci.cpp:231:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  231 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 28 ms 2940 KB Output is correct
8 Correct 29 ms 3012 KB Output is correct
9 Correct 27 ms 2988 KB Output is correct
10 Correct 27 ms 2936 KB Output is correct
11 Correct 33 ms 2960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 44 ms 5364 KB Output is correct
11 Correct 50 ms 5472 KB Output is correct
12 Correct 47 ms 5312 KB Output is correct
13 Correct 57 ms 5308 KB Output is correct
14 Correct 43 ms 5292 KB Output is correct
15 Correct 51 ms 5316 KB Output is correct
16 Correct 47 ms 5332 KB Output is correct
17 Correct 40 ms 4928 KB Output is correct
18 Correct 40 ms 4856 KB Output is correct
19 Correct 51 ms 4548 KB Output is correct
20 Correct 48 ms 4844 KB Output is correct
21 Correct 50 ms 5388 KB Output is correct
22 Correct 46 ms 5344 KB Output is correct
23 Correct 43 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 412 KB Output isn't correct
2 Halted 0 ms 0 KB -