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;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define INF 2023456789
#define LINF 1023456789123456789
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> ii;
#define maxn 300005
int n,k;
ll x[maxn],y[maxn];
inline int in(ll a,ll b,ll x,ll y,ll x2,ll y2){
return x<=a&&a<=x2&&y<=b&&b<=y2;
}
int main(){
sf("%d%d",&n,&k);
assert(k==1||n<=12);
for(int i=0;i<n;++i){
sf("%lld%lld",&x[i],&y[i]);
}
ll best=LINF;
vi ansx,ansy,ansl;
int msk=1;
for(int i=0;i<n;++i)msk*=k;
for(int m=0;m<msk;++m){
int tm=m;
vi mnx(k,LINF),mxx(k,-LINF),mny(k,LINF),mxy(k,-LINF);
for(int i=0;i<n;++i){
int c=tm%k;
tm/=k;
mnx[c]=min(mnx[c],x[i]);
mxx[c]=max(mxx[c],x[i]);
mny[c]=min(mny[c],y[i]);
mxy[c]=max(mxy[c],y[i]);
}
bool good=true;
int cnt=0;
for(int i=0;i<k;++i){
if(mnx[i]==LINF){
if(cnt==0)mnx[i]=mxx[i]=mny[i]=mxy[i]=-(ll)3*1e9;
else mnx[i]=mxx[i]=mny[i]=mxy[i]=(ll)3*1e9;
++cnt;
}
}
for(int i=0;i<k;++i){
for(int j=0;j<k;++j){
if(i==j)continue;
ll l=max(1ll,max(mxx[j]-mnx[j],mxy[j]-mny[j]));
if(in(mnx[i],mny[i],mnx[j],mny[j],mnx[j]+l,mny[j]+l))good=false;
if(in(mnx[i],mxy[i],mnx[j],mny[j],mnx[j]+l,mny[j]+l))good=false;
if(in(mxx[i],mny[i],mnx[j],mny[j],mnx[j]+l,mny[j]+l))good=false;
if(in(mxx[i],mxy[i],mnx[j],mny[j],mnx[j]+l,mny[j]+l))good=false;
}
}
if(good){
ll mx=0;
vi cx,cy,cl;
for(int i=0;i<k;++i){
cx.pb(mnx[i]);
cy.pb(mny[i]);
cl.pb(max(1ll,max(mxx[i]-mnx[i],mxy[i]-mny[i])));
mx=max(mx,cl.back());
}
if(mx<best){
best=mx;
swap(cx,ansx);
swap(cy,ansy);
swap(cl,ansl);
}
}
}
for(int i=0;i<k;++i){
pf("%lld %lld %lld\n",ansx[i],ansy[i],ansl[i]);
}
}
Compilation message (stderr)
izvanzemaljci.cpp: In function 'int main()':
izvanzemaljci.cpp:32:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | sf("%d%d",&n,&k);
| ^
izvanzemaljci.cpp:35:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | sf("%lld%lld",&x[i],&y[i]);
| ^
# | 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... |