Submission #569619

# Submission time Handle Problem Language Result Execution time Memory
569619 2022-05-27T14:54:58 Z inksamurai Road Construction (JOI21_road_construction) C++17
0 / 100
10000 ms 10720 KB
#include <bits/stdc++.h>
#define int long long 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3z2QF2y ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

#define all(a) a.begin(), a.end()

signed main(){
_3z2QF2y;
	int n,k;
	cin>>n>>k;
	
	k*=2;

	vec(pii) a(n);
	rep(i,n) cin>>a[i].fi>>a[i].se;
	
	vi xs,ys;
	rep(i,n){
		int u=a[i].fi-a[i].se,v=a[i].fi+a[i].se;
		xs.pb(u);
		ys.pb(v);
	}
	
	sort(all(xs));
	xs.erase(unique(all(xs)),xs.end());
	sort(all(ys));
	ys.erase(unique(all(ys)),ys.end());
	
	auto eval=[&](int x,int y,int d)->int{
		int res=0;
		rep(i,n){
			if(abs(a[i].fi-x)+abs(a[i].se-y)<=d) res+=1;
		}
		return res;
	};

	using T=pair<int,pii>;
	priority_queue<T,vec(T),greater<T>> pq;
	vi rbe(n,1);
	auto push=[&](int i){
		int l=1,r=1e9;
		int c=-1,val=-1;
		while(l<=r){
			int m=(l+r)/2;
			int nval=eval(a[i].fi,a[i].se,m);
			if(nval>rbe[i]){
				val=nval-rbe[i],c=m,r=m-1;
			}else{
				l=m+1;
			}
		}
		if(c!=-1){
			pq.push({c,{val,i}});
			rbe[i]+=val;
		}
	};

	rep(i,n){
		push(i);
	}

	vi pns;
	while(sz(pq) and k>0){
		auto top=pq.top();
		pq.pop();
		while(top.se.fi--){
			pns.pb(top.fi);
			k-=1;
		}
		push(top.se.se);
	}

	assert(sz(pns)%2==0);

	for(int i=0;i<sz(pns);i+=2){
		cout<<pns[i]<<"\n";
	}
//
	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 10025 ms 2552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10087 ms 10720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10083 ms 10716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10083 ms 10716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10025 ms 2552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10025 ms 2552 KB Time limit exceeded
2 Halted 0 ms 0 KB -