Submission #253861

# Submission time Handle Problem Language Result Execution time Memory
253861 2020-07-28T23:45:40 Z EntityIT Circle selection (APIO18_circle_selection) C++14
100 / 100
1226 ms 60352 KB
#include <bits/stdc++.h>
using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) static_cast<int>((x).size())

template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
      : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
      : vector<T>(args...) {}
};

template<class T>
inline bool Minimize(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool Maximize(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int Next(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int Prev(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng(static_cast<uint32_t>(chrono::steady_clock::now().time_since_epoch().count()));

struct Circle {
  int x, y, r;
  Circle(int t_x = 0, int t_y = 0, int t_r = 0)
      : x(t_x),
        y(t_y),
        r(t_r) {}

  bool CheckIntersection(const Circle& o) const {
    return static_cast<int64_t>(x - o.x) * (x - o.x) + static_cast<int64_t>(y - o.y) * (y - o.y) <= static_cast<int64_t>(r + o.r) * (r + o.r);
  }
};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  int n_circles; cin >> n_circles;
  vec<Circle, 1> circles(n_circles);
  int min_x, min_y;
  min_x = min_y = numeric_limits<int>::max();
  for (auto& circle : circles) {
    cin >> circle.x >> circle.y >> circle.r;
    Minimize(min_x, circle.x);
    Minimize(min_y, circle.y);
  }
  for (auto& circle : circles) {
    circle.x -= min_x;
    circle.y -= min_y;
  }

  vec<int, 1> ord_circles(n_circles); iota(ALL(ord_circles), 0);
  sort(ALL(ord_circles), [&](int i, int j) {
    return circles[i].r != circles[j].r ? circles[i].r > circles[j].r : i < j;
  });

  int scaler = 31;
  vec<pair<int, int>, 2> members_groups(1);
  for (int i = 0; i < n_circles; ++i) {
    members_groups[0].emplace_back(circles[i].y, i);
  }
  sort(ALL(members_groups[0]));

  vec<char, 1> deleted(n_circles);
  vec<int, 1> answers(n_circles);
  for (auto& idx_circle : ord_circles) {
    if (!deleted[idx_circle]) {
      deleted[idx_circle] = true;
      answers[idx_circle] = idx_circle;

      while (scaler && circles[idx_circle].r <= (1 << (scaler - 1))) {
        --scaler;

        vec<pair<int, int>, 2> next_members_groups(SZ(members_groups) << 1);
        int i = 0;
        for (auto& members : members_groups) {
          for (auto& member : members) {
            if (deleted[member.second]) {
              continue;
            }
            next_members_groups[i + ((circles[member.second].x >> scaler) & 1)].emplace_back(member);
          }
          i += 2;
        }
        next_members_groups.erase(remove_if(ALL(next_members_groups), [&](const vec<pair<int, int>, 1>& x) { return !SZ(x); }), next_members_groups.end());
        members_groups.swap(next_members_groups);
      }

      for (auto it_members_groups = lower_bound(ALL(members_groups), (circles[idx_circle].x >> scaler) - 2, [&](const vec<pair<int, int>, 1>& i, const int& j) { return (circles[i[0].second].x >> scaler) < j; }); it_members_groups != members_groups.end() && (circles[(*it_members_groups)[0].second].x >> scaler) <= (circles[idx_circle].x >> scaler) + 2; ++it_members_groups) {
        for (auto it_members = lower_bound(ALL(*it_members_groups), (circles[idx_circle].y >> scaler) - 2, [&](const pair<int, int>& i, const int& j) { return (i.first >> scaler) < j; });
        it_members != it_members_groups->end() && (it_members->first >> scaler) <= (circles[idx_circle].y >> scaler) + 2; ++it_members) {
          if (!deleted[it_members->second] && circles[idx_circle].CheckIntersection(circles[it_members->second])) {
            deleted[it_members->second] = true;
            answers[it_members->second] = idx_circle;
          }
        }
      }
    }
  }

  for (auto& answer : answers) {
    cout << answer + 1 << ' ';
  }
  cout << '\n';

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 9 ms 1024 KB Output is correct
23 Correct 8 ms 768 KB Output is correct
24 Correct 8 ms 1148 KB Output is correct
25 Correct 11 ms 1360 KB Output is correct
26 Correct 9 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 15848 KB Output is correct
2 Correct 222 ms 15880 KB Output is correct
3 Correct 202 ms 17048 KB Output is correct
4 Correct 184 ms 13932 KB Output is correct
5 Correct 319 ms 16284 KB Output is correct
6 Correct 493 ms 26104 KB Output is correct
7 Correct 337 ms 16748 KB Output is correct
8 Correct 383 ms 18168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 158 ms 7004 KB Output is correct
3 Correct 627 ms 22988 KB Output is correct
4 Correct 658 ms 21096 KB Output is correct
5 Correct 537 ms 16092 KB Output is correct
6 Correct 228 ms 9756 KB Output is correct
7 Correct 118 ms 6376 KB Output is correct
8 Correct 24 ms 2468 KB Output is correct
9 Correct 716 ms 18992 KB Output is correct
10 Correct 554 ms 16816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 657 ms 19060 KB Output is correct
2 Correct 1226 ms 54340 KB Output is correct
3 Correct 324 ms 15848 KB Output is correct
4 Correct 899 ms 44376 KB Output is correct
5 Correct 957 ms 50640 KB Output is correct
6 Correct 311 ms 19244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 9 ms 1024 KB Output is correct
23 Correct 8 ms 768 KB Output is correct
24 Correct 8 ms 1148 KB Output is correct
25 Correct 11 ms 1360 KB Output is correct
26 Correct 9 ms 1280 KB Output is correct
27 Correct 8 ms 1152 KB Output is correct
28 Correct 8 ms 1276 KB Output is correct
29 Correct 12 ms 1276 KB Output is correct
30 Correct 20 ms 1416 KB Output is correct
31 Correct 16 ms 1760 KB Output is correct
32 Correct 20 ms 1812 KB Output is correct
33 Correct 88 ms 5616 KB Output is correct
34 Correct 80 ms 5616 KB Output is correct
35 Correct 85 ms 5856 KB Output is correct
36 Correct 186 ms 10708 KB Output is correct
37 Correct 191 ms 10180 KB Output is correct
38 Correct 168 ms 9372 KB Output is correct
39 Correct 217 ms 7068 KB Output is correct
40 Correct 215 ms 7128 KB Output is correct
41 Correct 212 ms 7340 KB Output is correct
42 Correct 127 ms 6724 KB Output is correct
43 Correct 217 ms 17708 KB Output is correct
44 Correct 212 ms 17572 KB Output is correct
45 Correct 212 ms 17588 KB Output is correct
46 Correct 207 ms 17576 KB Output is correct
47 Correct 231 ms 17572 KB Output is correct
48 Correct 210 ms 17568 KB Output is correct
49 Correct 224 ms 17572 KB Output is correct
50 Correct 225 ms 17476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 9 ms 1024 KB Output is correct
23 Correct 8 ms 768 KB Output is correct
24 Correct 8 ms 1148 KB Output is correct
25 Correct 11 ms 1360 KB Output is correct
26 Correct 9 ms 1280 KB Output is correct
27 Correct 203 ms 15848 KB Output is correct
28 Correct 222 ms 15880 KB Output is correct
29 Correct 202 ms 17048 KB Output is correct
30 Correct 184 ms 13932 KB Output is correct
31 Correct 319 ms 16284 KB Output is correct
32 Correct 493 ms 26104 KB Output is correct
33 Correct 337 ms 16748 KB Output is correct
34 Correct 383 ms 18168 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 158 ms 7004 KB Output is correct
37 Correct 627 ms 22988 KB Output is correct
38 Correct 658 ms 21096 KB Output is correct
39 Correct 537 ms 16092 KB Output is correct
40 Correct 228 ms 9756 KB Output is correct
41 Correct 118 ms 6376 KB Output is correct
42 Correct 24 ms 2468 KB Output is correct
43 Correct 716 ms 18992 KB Output is correct
44 Correct 554 ms 16816 KB Output is correct
45 Correct 657 ms 19060 KB Output is correct
46 Correct 1226 ms 54340 KB Output is correct
47 Correct 324 ms 15848 KB Output is correct
48 Correct 899 ms 44376 KB Output is correct
49 Correct 957 ms 50640 KB Output is correct
50 Correct 311 ms 19244 KB Output is correct
51 Correct 8 ms 1152 KB Output is correct
52 Correct 8 ms 1276 KB Output is correct
53 Correct 12 ms 1276 KB Output is correct
54 Correct 20 ms 1416 KB Output is correct
55 Correct 16 ms 1760 KB Output is correct
56 Correct 20 ms 1812 KB Output is correct
57 Correct 88 ms 5616 KB Output is correct
58 Correct 80 ms 5616 KB Output is correct
59 Correct 85 ms 5856 KB Output is correct
60 Correct 186 ms 10708 KB Output is correct
61 Correct 191 ms 10180 KB Output is correct
62 Correct 168 ms 9372 KB Output is correct
63 Correct 217 ms 7068 KB Output is correct
64 Correct 215 ms 7128 KB Output is correct
65 Correct 212 ms 7340 KB Output is correct
66 Correct 127 ms 6724 KB Output is correct
67 Correct 217 ms 17708 KB Output is correct
68 Correct 212 ms 17572 KB Output is correct
69 Correct 212 ms 17588 KB Output is correct
70 Correct 207 ms 17576 KB Output is correct
71 Correct 231 ms 17572 KB Output is correct
72 Correct 210 ms 17568 KB Output is correct
73 Correct 224 ms 17572 KB Output is correct
74 Correct 225 ms 17476 KB Output is correct
75 Correct 268 ms 15712 KB Output is correct
76 Correct 296 ms 15960 KB Output is correct
77 Correct 286 ms 18112 KB Output is correct
78 Correct 259 ms 15596 KB Output is correct
79 Correct 317 ms 15588 KB Output is correct
80 Correct 250 ms 15592 KB Output is correct
81 Correct 732 ms 18764 KB Output is correct
82 Correct 802 ms 24564 KB Output is correct
83 Correct 680 ms 23508 KB Output is correct
84 Correct 643 ms 19404 KB Output is correct
85 Correct 645 ms 21432 KB Output is correct
86 Correct 686 ms 25392 KB Output is correct
87 Correct 598 ms 16248 KB Output is correct
88 Correct 775 ms 19704 KB Output is correct
89 Correct 785 ms 19620 KB Output is correct
90 Correct 1053 ms 19412 KB Output is correct
91 Correct 790 ms 19728 KB Output is correct
92 Correct 778 ms 21288 KB Output is correct
93 Correct 1034 ms 52448 KB Output is correct
94 Correct 684 ms 15608 KB Output is correct
95 Correct 1030 ms 59504 KB Output is correct
96 Correct 1029 ms 57988 KB Output is correct
97 Correct 837 ms 22264 KB Output is correct
98 Correct 633 ms 33784 KB Output is correct
99 Correct 1183 ms 60012 KB Output is correct
100 Correct 1193 ms 60352 KB Output is correct
101 Correct 688 ms 30328 KB Output is correct
102 Correct 1057 ms 57016 KB Output is correct
103 Correct 658 ms 23160 KB Output is correct
104 Correct 1038 ms 59948 KB Output is correct
105 Correct 477 ms 23424 KB Output is correct
106 Correct 832 ms 43000 KB Output is correct
107 Correct 773 ms 43000 KB Output is correct
108 Correct 753 ms 42872 KB Output is correct
109 Correct 751 ms 42872 KB Output is correct
110 Correct 746 ms 42744 KB Output is correct
111 Correct 734 ms 42948 KB Output is correct
112 Correct 734 ms 42820 KB Output is correct
113 Correct 823 ms 42616 KB Output is correct
114 Correct 858 ms 42616 KB Output is correct
115 Correct 841 ms 42872 KB Output is correct
116 Correct 947 ms 53648 KB Output is correct