답안 #879970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879970 2023-11-28T12:17:02 Z willychan Road Construction (JOI21_road_construction) C++17
100 / 100
4621 ms 11368 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define x first
#define y second
struct bit{
	vector<int> arr;
	int n;
	void init(int _n){
		arr.resize(_n+1,0);
		n = _n;
	}
	void modify(int ind,int v){
		while(ind<=n){
			arr[ind]+=v;
			ind+=(ind&-ind);
		}
	}
	int query(int ind){
		int ans = 0;
		while(ind){
			ans+=arr[ind];
			ind-=(ind&-ind);
		}
		return ans;
	}
};

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;cin>>n;
	int k;cin>>k;
	pair<ll,ll> arr[n];
	for(int i=0;i<n;i++) cin>>arr[i].x>>arr[i].y;
	for(int i=0;i<n;i++){
		arr[i].x = arr[i].x+arr[i].y;
		arr[i].y = arr[i].x-2*arr[i].y;
	}
	sort(arr,arr+n);
	vector<ll> d;
	for(int i=0;i<n;i++) d.push_back(arr[i].y);
	sort(d.begin(),d.end());
	d.resize(unique(d.begin(),d.end())-d.begin());
	bit B;
	B.init(d.size());
	ll l = 0;
	ll r = 1e10;
	while(r-l>1){
		ll mid = (l+r)/2;
		ll cnt = 0;
		int head = 0;
		B.modify(lower_bound(d.begin(),d.end(),arr[0].y)-d.begin()+1,1);
		for(int i=1;i<n;i++){
			while(head<i && arr[head].x<arr[i].x-mid){
				B.modify(lower_bound(d.begin(),d.end(),arr[head].y)-d.begin()+1,-1);
				head++;
			}
			int qr = upper_bound(d.begin(),d.end(),arr[i].y+mid)-d.begin();
			int ql = lower_bound(d.begin(),d.end(),arr[i].y-mid)-d.begin()+1;
			cnt+=B.query(qr)-B.query(ql-1);
			B.modify(lower_bound(d.begin(),d.end(),arr[i].y)-d.begin()+1,1);
		}
		fill(B.arr.begin(),B.arr.end(),0);
		if(cnt>=k) r = mid;
		else l = mid;
	}
	vector<ll> ans;
	set<pair<ll,ll> > s;
	s.insert(make_pair(arr[0].y,0));
	int head = 0;
	for(int i=1;i<n;i++)	{
		while(head<i && arr[head].x<arr[i].x-l){
			auto it = s.find(make_pair(arr[head].y,head));
			s.erase(it);
			head++;
		}
		auto it = s.upper_bound(make_pair(arr[i].y-l,-1));	
		for(;it!=s.end() && it->first<=arr[i].y+l; ++it){
			int j = it->second;
			ans.push_back(max(abs(arr[i].x-arr[j].x),abs(arr[i].y-arr[j].y)));
		}
		s.insert(make_pair(arr[i].y,i));
	}
	sort(ans.begin(),ans.end());
	assert(ans.size()<=k);
	int left = k-ans.size();
	for(auto i : ans) cout<<i<<"\n";
	for(int i=0;i<left;i++) cout<<r<<"\n";
	return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from road_construction.cpp:1:
road_construction.cpp: In function 'int main()':
road_construction.cpp:87:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |  assert(ans.size()<=k);
      |         ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5068 KB Output is correct
2 Correct 39 ms 5068 KB Output is correct
3 Correct 44 ms 5072 KB Output is correct
4 Correct 33 ms 5204 KB Output is correct
5 Correct 43 ms 3872 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1852 ms 10564 KB Output is correct
2 Correct 1842 ms 10520 KB Output is correct
3 Correct 31 ms 5068 KB Output is correct
4 Correct 1861 ms 10364 KB Output is correct
5 Correct 1780 ms 10500 KB Output is correct
6 Correct 1799 ms 10496 KB Output is correct
7 Correct 1780 ms 10368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4050 ms 7112 KB Output is correct
2 Correct 4081 ms 7292 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1771 ms 7284 KB Output is correct
5 Correct 1509 ms 6356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4050 ms 7112 KB Output is correct
2 Correct 4081 ms 7292 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1771 ms 7284 KB Output is correct
5 Correct 1509 ms 6356 KB Output is correct
6 Correct 4172 ms 7120 KB Output is correct
7 Correct 4078 ms 7116 KB Output is correct
8 Correct 0 ms 500 KB Output is correct
9 Correct 1 ms 500 KB Output is correct
10 Correct 4110 ms 7116 KB Output is correct
11 Correct 1746 ms 7124 KB Output is correct
12 Correct 1506 ms 6356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5068 KB Output is correct
2 Correct 39 ms 5068 KB Output is correct
3 Correct 44 ms 5072 KB Output is correct
4 Correct 33 ms 5204 KB Output is correct
5 Correct 43 ms 3872 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1645 ms 7180 KB Output is correct
8 Correct 1603 ms 7268 KB Output is correct
9 Correct 34 ms 5084 KB Output is correct
10 Correct 1466 ms 6352 KB Output is correct
11 Correct 1379 ms 6328 KB Output is correct
12 Correct 357 ms 4812 KB Output is correct
13 Correct 543 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5068 KB Output is correct
2 Correct 39 ms 5068 KB Output is correct
3 Correct 44 ms 5072 KB Output is correct
4 Correct 33 ms 5204 KB Output is correct
5 Correct 43 ms 3872 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1852 ms 10564 KB Output is correct
8 Correct 1842 ms 10520 KB Output is correct
9 Correct 31 ms 5068 KB Output is correct
10 Correct 1861 ms 10364 KB Output is correct
11 Correct 1780 ms 10500 KB Output is correct
12 Correct 1799 ms 10496 KB Output is correct
13 Correct 1780 ms 10368 KB Output is correct
14 Correct 4050 ms 7112 KB Output is correct
15 Correct 4081 ms 7292 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1771 ms 7284 KB Output is correct
18 Correct 1509 ms 6356 KB Output is correct
19 Correct 4172 ms 7120 KB Output is correct
20 Correct 4078 ms 7116 KB Output is correct
21 Correct 0 ms 500 KB Output is correct
22 Correct 1 ms 500 KB Output is correct
23 Correct 4110 ms 7116 KB Output is correct
24 Correct 1746 ms 7124 KB Output is correct
25 Correct 1506 ms 6356 KB Output is correct
26 Correct 1645 ms 7180 KB Output is correct
27 Correct 1603 ms 7268 KB Output is correct
28 Correct 34 ms 5084 KB Output is correct
29 Correct 1466 ms 6352 KB Output is correct
30 Correct 1379 ms 6328 KB Output is correct
31 Correct 357 ms 4812 KB Output is correct
32 Correct 543 ms 5496 KB Output is correct
33 Correct 4507 ms 11368 KB Output is correct
34 Correct 4621 ms 11272 KB Output is correct
35 Correct 4025 ms 10280 KB Output is correct
36 Correct 1303 ms 7984 KB Output is correct
37 Correct 1354 ms 8236 KB Output is correct
38 Correct 1690 ms 9276 KB Output is correct