답안 #946972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946972 2024-03-15T08:49:42 Z siewjh Road Construction (JOI21_road_construction) C++17
0 / 100
133 ms 7632 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();
	multiset<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(active.find({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';
      |                                                      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 5336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 133 ms 7632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 4180 KB Output is correct
2 Incorrect 95 ms 7152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 4180 KB Output is correct
2 Incorrect 95 ms 7152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 5336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 5336 KB Output isn't correct
2 Halted 0 ms 0 KB -