Submission #567997

# Submission time Handle Problem Language Result Execution time Memory
567997 2022-05-24T13:28:45 Z Arvin Road Construction (JOI21_road_construction) C++11
38 / 100
10000 ms 67576 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll maxA = 1e13;
const int maxN = 3e5;

pair<ll, ll> p[maxN], q[maxN];
vector<ll> cX[maxN], cY[maxN];

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//	freopen("input.txt","r",stdin);
	
	int n, k;
	cin >> n >> k;
	
	for(int x=0;x<n;x++){
		cin >> p[x].first >> p[x].second;
		p[x] = {p[x].first+p[x].second+maxA, p[x].first-p[x].second+maxA};
	}
	
	vector<ll> vX, vY;
	priority_queue<array<ll, 4>, vector<array<ll, 4>>, greater<array<ll, 4>>> pq;
	for(int x=0;x<n;x++){
		vX.push_back(p[x].first);
		vY.push_back(p[x].second);
	}
	
	sort(vX.begin(), vX.end());
	sort(vY.begin(), vY.end());
	vX.erase(unique(vX.begin(), vX.end()), vX.end());
	vY.erase(unique(vY.begin(), vY.end()), vY.end());
	
	for(int x=0;x<maxN;x++){
		cX[x].push_back(3*maxA);
		cY[x].push_back(3*maxA);
	}
	for(int x=0;x<n;x++){
		q[x] = {lower_bound(vX.begin(), vX.end(), p[x].first) - vX.begin(), lower_bound(vY.begin(), vY.end(), p[x].second) - vY.begin()};
		cX[q[x].first].push_back(p[x].second);
		cY[q[x].second].push_back(p[x].first);
	}
	for(int x=0;x<maxN;x++){
		sort(cX[x].begin(), cX[x].end());
		sort(cY[x].begin(), cY[x].end());
	}
	
	for(int x=0;x<n;x++){	
		if(q[x].first+1 < vX.size()){
			ll dif = abs(vX[q[x].first+1] - p[x].first);
//			int idx = lower_bound(cX[q[x].first+1].begin(), cX[q[x].first+1].end(), p[x].second-dif) - cX[q[x].first+1].begin();
			pq.push({dif, 0, x, q[x].first+1});
		}
		if(q[x].second+1 < vY.size()){
			ll dif = abs(vY[q[x].second+1] - p[x].second);
//			int idx = lower_bound(cY[q[x].second+1].begin(), cY[q[x].second+1].end(), p[x].first-dif+1) - cY[q[x].second+1].begin();
			pq.push({dif, 1, x, q[x].second+1});
		}
	}
	
	while(k > 0 && !pq.empty()){
		ll val = pq.top()[0], type = pq.top()[1], idx = pq.top()[2], r = pq.top()[3], idx2 = pq.top()[4];
		pq.pop();
		
		if(type == 0){
			ll dif = abs(vX[r] - p[idx].first);
			
			int idxL = lower_bound(cX[r].begin(), cX[r].end(), p[idx].second-dif) - cX[r].begin();
			int idxR = lower_bound(cX[r].begin(), cX[r].end(), p[idx].second+dif+1) - cX[r].begin();
			
			for(int i=0;i<idxR-idxL&&k>0;i++){
				cout << val << "\n";
				k--;
			}
			if(r+1 >= vX.size()) continue;
			
			dif = abs(vX[r+1] - p[idx].first);
			pq.push({dif, 0, idx, r+1});
		} else {
			ll dif = abs(vY[r] - p[idx].second);
			
			int idxL = lower_bound(cY[r].begin(), cY[r].end(), p[idx].first-dif+1) - cY[r].begin();
			int idxR = lower_bound(cY[r].begin(), cY[r].end(), p[idx].first+dif) - cY[r].begin();
			
			for(int i=0;i<idxR-idxL&&k>0;i++){
				cout << val << "\n";
				k--;
			}

			if(r+1 >= vY.size()) continue;
			
			dif = abs(vY[r+1] - p[idx].second);
			pq.push({dif, 1, idx, r+1});
		}
	}
    return 0;
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:54:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   if(q[x].first+1 < vX.size()){
      |      ~~~~~~~~~~~~~^~~~~~~~~~~
road_construction.cpp:59:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   if(q[x].second+1 < vY.size()){
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~
road_construction.cpp:80:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |    if(r+1 >= vX.size()) continue;
      |       ~~~~^~~~~~~~~~~~
road_construction.cpp:95:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |    if(r+1 >= vY.size()) continue;
      |       ~~~~^~~~~~~~~~~~
road_construction.cpp:67:81: warning: unused variable 'idx2' [-Wunused-variable]
   67 |   ll val = pq.top()[0], type = pq.top()[1], idx = pq.top()[2], r = pq.top()[3], idx2 = pq.top()[4];
      |                                                                                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 163 ms 35872 KB Output is correct
2 Correct 160 ms 35844 KB Output is correct
3 Correct 121 ms 36052 KB Output is correct
4 Correct 125 ms 36044 KB Output is correct
5 Correct 139 ms 34956 KB Output is correct
6 Correct 39 ms 33364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 674 ms 61888 KB Output is correct
2 Correct 632 ms 62008 KB Output is correct
3 Correct 126 ms 35804 KB Output is correct
4 Correct 550 ms 61788 KB Output is correct
5 Correct 546 ms 61964 KB Output is correct
6 Correct 537 ms 61892 KB Output is correct
7 Correct 562 ms 61460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 61428 KB Output is correct
2 Correct 685 ms 61484 KB Output is correct
3 Correct 38 ms 33108 KB Output is correct
4 Correct 367 ms 61528 KB Output is correct
5 Correct 202 ms 67576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 61428 KB Output is correct
2 Correct 685 ms 61484 KB Output is correct
3 Correct 38 ms 33108 KB Output is correct
4 Correct 367 ms 61528 KB Output is correct
5 Correct 202 ms 67576 KB Output is correct
6 Correct 1098 ms 61524 KB Output is correct
7 Correct 964 ms 61512 KB Output is correct
8 Correct 37 ms 33108 KB Output is correct
9 Correct 37 ms 33120 KB Output is correct
10 Correct 595 ms 63120 KB Output is correct
11 Correct 361 ms 61516 KB Output is correct
12 Correct 200 ms 67480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 35872 KB Output is correct
2 Correct 160 ms 35844 KB Output is correct
3 Correct 121 ms 36052 KB Output is correct
4 Correct 125 ms 36044 KB Output is correct
5 Correct 139 ms 34956 KB Output is correct
6 Correct 39 ms 33364 KB Output is correct
7 Execution timed out 10073 ms 46232 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 163 ms 35872 KB Output is correct
2 Correct 160 ms 35844 KB Output is correct
3 Correct 121 ms 36052 KB Output is correct
4 Correct 125 ms 36044 KB Output is correct
5 Correct 139 ms 34956 KB Output is correct
6 Correct 39 ms 33364 KB Output is correct
7 Correct 674 ms 61888 KB Output is correct
8 Correct 632 ms 62008 KB Output is correct
9 Correct 126 ms 35804 KB Output is correct
10 Correct 550 ms 61788 KB Output is correct
11 Correct 546 ms 61964 KB Output is correct
12 Correct 537 ms 61892 KB Output is correct
13 Correct 562 ms 61460 KB Output is correct
14 Correct 585 ms 61428 KB Output is correct
15 Correct 685 ms 61484 KB Output is correct
16 Correct 38 ms 33108 KB Output is correct
17 Correct 367 ms 61528 KB Output is correct
18 Correct 202 ms 67576 KB Output is correct
19 Correct 1098 ms 61524 KB Output is correct
20 Correct 964 ms 61512 KB Output is correct
21 Correct 37 ms 33108 KB Output is correct
22 Correct 37 ms 33120 KB Output is correct
23 Correct 595 ms 63120 KB Output is correct
24 Correct 361 ms 61516 KB Output is correct
25 Correct 200 ms 67480 KB Output is correct
26 Execution timed out 10073 ms 46232 KB Time limit exceeded
27 Halted 0 ms 0 KB -