답안 #969327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969327 2024-04-25T01:33:14 Z abczz Road Construction (JOI21_road_construction) C++14
0 / 100
3877 ms 27988 KB
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <map>
#define ll long long

using namespace std;

ll n, k, f;
vector <ll> V;
map <pair<ll, ll>, ll> mp;
array <ll, 2> A[250000];
void solve(ll mid) {
  V.clear();
  mp.clear();
  f = 0;
  for (int i=0; i<n; ++i) {
    auto it = mp.lower_bound({A[i][0]-A[i][1]-mid, 0});
    while (it != mp.end()) {
      if (it->first.first > A[i][0]-A[i][1]+mid) break;
      auto nx = next(it);
      if (it->first.second + mid < A[i][0]+A[i][1]) mp.erase(it);
      else {
        auto x = (it->first.first+it->first.second)/2;
        V.push_back(A[i][0]-x+abs(A[i][1]-it->first.second+x));
        if (V.size() > k) break;
      }
      it = nx;
    }
    ++mp[{A[i][0]-A[i][1], A[i][0]+A[i][1]}];
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i=0; i<n; ++i) {
    cin >> A[i][0] >> A[i][1];
  }
  sort(A, A+n, [](auto a, auto b) {
    return a[0]+a[1] < b[0]+b[1];
  });
  ll l = 0, r = (ll)4e9, mid;
  while (l < r) {
    mid = (l+r)/2;
    solve(mid);
    if (V.size() < k) l = mid+1;
    else r = mid;
  }
  solve(l);
  sort(V.begin(), V.end());
  for (int i=0; i<k; ++i) {
    cout << V[i] << '\n';
  }
}

Compilation message

road_construction.cpp: In function 'void solve(long long int)':
road_construction.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   27 |         if (V.size() > k) break;
      |             ~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:48:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |     if (V.size() < k) l = mid+1;
      |         ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 5164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2059 ms 27988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3877 ms 26828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3877 ms 26828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 5164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 5164 KB Output isn't correct
2 Halted 0 ms 0 KB -