Submission #946968

# Submission time Handle Problem Language Result Execution time Memory
946968 2024-03-15T08:44:16 Z siewjh Road Construction (JOI21_road_construction) C++17
0 / 100
143 ms 7480 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 250005;
const ll inf = 1e18;
pair<ll, ll> arr[MAXN];
vector<ll> dvec;
int nums, k; 
bool gen(ll d){
	dvec.clear();
	set<pair<ll, ll>> active;
	int lind = 0;
	for (int i = 0; i < nums; i++){
		ll x, y; tie(x, y) = arr[i];
		while (arr[lind].first < x - d){
			active.erase({arr[lind].second, arr[lind].first});
			lind++;
		}
		for (auto it = active.lower_bound({y - d, -inf}); it != active.end() && it->first <= y + d; it++){
			dvec.push_back(max(abs(x - it->second), abs(y - it->first)));
			if (dvec.size() > k) return 0;
		}
		active.insert({y, x});
	}
	return 1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> nums >> k;
	for (int i = 0; i < nums; i++){
		ll x, y; cin >> x >> y;
		arr[i] = {x + y, x - y};
	}
	sort(arr, arr + nums);
	ll l = 0, r = 4e9, ans;
	while (l <= r){
		ll m = (l + r) >> 1;
		if (gen(m)){
			ans = m;
			l = m + 1;
		}
		r = m - 1;
	}
	gen(ans);
	sort(dvec.begin(), dvec.end());
	for (ll x : dvec) cout << x << '\n';
	for (int i = dvec.size(); i < k; i++) cout << ans + 1 << '\n';
}

Compilation message

road_construction.cpp: In function 'bool gen(ll)':
road_construction.cpp:21:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |    if (dvec.size() > k) return 0;
      |        ~~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:48:54: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |  for (int i = dvec.size(); i < k; i++) cout << ans + 1 << '\n';
      |                                                      ^
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 143 ms 7480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 4188 KB Output is correct
2 Incorrect 109 ms 4348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 4188 KB Output is correct
2 Incorrect 109 ms 4348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -