답안 #969337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969337 2024-04-25T02:35:46 Z abczz Road Construction (JOI21_road_construction) C++14
100 / 100
1966 ms 28448 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, bool b) {
  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(abs(A[i][0]-x)+abs(A[i][1]-it->first.second+x));
        if (b && V.size() > k) break;
      }
      it = nx;
    }
    if (b && V.size() > k) break;
    ++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, 1);
    if (V.size() < k) l = mid+1;
    else r = mid;
  }
  solve(l, 0);
  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, bool)':
road_construction.cpp:27:27: 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 (b && V.size() > k) break;
      |                  ~~~~~~~~~^~~
road_construction.cpp:31:23: 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]
   31 |     if (b && V.size() > k) break;
      |              ~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:49: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]
   49 |     if (V.size() < k) l = mid+1;
      |         ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 5140 KB Output is correct
2 Correct 89 ms 5068 KB Output is correct
3 Correct 80 ms 5068 KB Output is correct
4 Correct 89 ms 5132 KB Output is correct
5 Correct 88 ms 3852 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 941 ms 23008 KB Output is correct
2 Correct 1000 ms 26184 KB Output is correct
3 Correct 77 ms 5072 KB Output is correct
4 Correct 762 ms 27824 KB Output is correct
5 Correct 885 ms 28116 KB Output is correct
6 Correct 842 ms 28368 KB Output is correct
7 Correct 745 ms 28448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1966 ms 16152 KB Output is correct
2 Correct 1673 ms 13428 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 659 ms 22052 KB Output is correct
5 Correct 475 ms 6576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1966 ms 16152 KB Output is correct
2 Correct 1673 ms 13428 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 659 ms 22052 KB Output is correct
5 Correct 475 ms 6576 KB Output is correct
6 Correct 1524 ms 10600 KB Output is correct
7 Correct 1509 ms 10460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1689 ms 13792 KB Output is correct
11 Correct 384 ms 21840 KB Output is correct
12 Correct 461 ms 4352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 5140 KB Output is correct
2 Correct 89 ms 5068 KB Output is correct
3 Correct 80 ms 5068 KB Output is correct
4 Correct 89 ms 5132 KB Output is correct
5 Correct 88 ms 3852 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 661 ms 6820 KB Output is correct
8 Correct 626 ms 6648 KB Output is correct
9 Correct 80 ms 5072 KB Output is correct
10 Correct 564 ms 6348 KB Output is correct
11 Correct 553 ms 10444 KB Output is correct
12 Correct 429 ms 10704 KB Output is correct
13 Correct 391 ms 9316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 5140 KB Output is correct
2 Correct 89 ms 5068 KB Output is correct
3 Correct 80 ms 5068 KB Output is correct
4 Correct 89 ms 5132 KB Output is correct
5 Correct 88 ms 3852 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 941 ms 23008 KB Output is correct
8 Correct 1000 ms 26184 KB Output is correct
9 Correct 77 ms 5072 KB Output is correct
10 Correct 762 ms 27824 KB Output is correct
11 Correct 885 ms 28116 KB Output is correct
12 Correct 842 ms 28368 KB Output is correct
13 Correct 745 ms 28448 KB Output is correct
14 Correct 1966 ms 16152 KB Output is correct
15 Correct 1673 ms 13428 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 659 ms 22052 KB Output is correct
18 Correct 475 ms 6576 KB Output is correct
19 Correct 1524 ms 10600 KB Output is correct
20 Correct 1509 ms 10460 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1689 ms 13792 KB Output is correct
24 Correct 384 ms 21840 KB Output is correct
25 Correct 461 ms 4352 KB Output is correct
26 Correct 661 ms 6820 KB Output is correct
27 Correct 626 ms 6648 KB Output is correct
28 Correct 80 ms 5072 KB Output is correct
29 Correct 564 ms 6348 KB Output is correct
30 Correct 553 ms 10444 KB Output is correct
31 Correct 429 ms 10704 KB Output is correct
32 Correct 391 ms 9316 KB Output is correct
33 Correct 1339 ms 13328 KB Output is correct
34 Correct 1326 ms 13328 KB Output is correct
35 Correct 1579 ms 13472 KB Output is correct
36 Correct 729 ms 19396 KB Output is correct
37 Correct 765 ms 18532 KB Output is correct
38 Correct 743 ms 15624 KB Output is correct