답안 #744183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744183 2023-05-18T09:01:52 Z jamielim Izvanzemaljci (COI21_izvanzemaljci) C++14
5 / 100
35 ms 3364 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};
}

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<ll> ans[2];
		ll le=find_one_square(all)[2];
		if(n==1){
			printf("%d %d 1\n3000000000 3000000000 1\n",x,y);
			return 0;
		}
		sort(ALL(all));
		for(int i=0;i<n;i++){
			if(i==0){
				premin[i]=all[i].se;
				premax[i]=all[i].se;
			}else{
				premin[i]=min(premin[i-1],all[i].se);
				premax[i]=max(premax[i-1],all[i].se);
			}
		}
		for(int i=n-1;i>=0;i--){
			if(i==n-1){
				sufmin[i]=all[i].se;
				sufmax[i]=all[i].se;
			}else{
				sufmin[i]=min(sufmin[i+1],all[i].se);
				sufmax[i]=max(sufmax[i+1],all[i].se);
			}
		}
		for(int i=0;i<n-1;i++){
			ll hor=max(max(all[i].fi-all[0].fi,all[n-1].fi-all[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;
				ans[0]={all[i].fi-l,premax[i]-l,l};
				ans[1]={all[i+1].fi,sufmin[i+1],l};
			}
		}
		
		for(int i=0;i<n;i++)swap(all[i].fi,all[i].se);
		sort(ALL(all));
		for(int i=0;i<n;i++){
			if(i==0){
				premin[i]=all[i].se;
				premax[i]=all[i].se;
			}else{
				premin[i]=min(premin[i-1],all[i].se);
				premax[i]=max(premax[i-1],all[i].se);
			}
		}
		for(int i=n-1;i>=0;i--){
			if(i==n-1){
				sufmin[i]=all[i].se;
				sufmax[i]=all[i].se;
			}else{
				sufmin[i]=min(sufmin[i+1],all[i].se);
				sufmax[i]=max(sufmax[i+1],all[i].se);
			}
		}
		for(int i=0;i<n-1;i++){
			ll hor=max(max(all[i].fi-all[0].fi,all[n-1].fi-all[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;
				ans[0]={premax[i]-l,all[i].fi-l,l};
				ans[1]={sufmin[i+1],all[i+1].fi,l};
			}
		}
		
		for(int i=0;i<2;i++){for(int j=0;j<3;j++)printf("%lld ",ans[i][j]);printf("\n");}
	}else{
		
	}
}
/*
5 2
1 3
3 1
5 5
5 10
7 7
*/

Compilation message

izvanzemaljci.cpp: In function 'int32_t main()':
izvanzemaljci.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
izvanzemaljci.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   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 308 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 30 ms 3308 KB Output is correct
8 Correct 35 ms 3280 KB Output is correct
9 Correct 32 ms 3296 KB Output is correct
10 Correct 34 ms 3316 KB Output is correct
11 Correct 29 ms 3364 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 Runtime error 1 ms 340 KB Execution killed with signal 11
4 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 340 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 320 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -