Submission #235106

# Submission time Handle Problem Language Result Execution time Memory
235106 2020-05-27T05:20:53 Z rama_pang Circle selection (APIO18_circle_selection) C++14
7 / 100
2809 ms 46712 KB
#include <bits/stdc++.h>
using namespace std;

struct Circle {
  int x, y, r, id;
  Circle() {}
  Circle(int x, int y, int r, int id) : x(x), y(y), r(r), id(id) {}
  bool operator < (const Circle &o) const { return r > o.r; }
};

bool Intersect(Circle a, Circle b) {
  return (1ll * (b.x - a.x) * (b.x - a.x) + 
          1ll * (b.y - a.y) * (b.y - a.y) <= 
          1ll * (b.r + a.r) * (b.r + a.r));
}

using Point = pair<int, int>;

int N;
vector<Circle> circles;

vector<int> revpos;
vector<bool> deleted;
vector<int> answer;

vector<pair<Point, vector<int>>> areas;

void Resize(int lg) {
  int side = 1 << lg;
  vector<Point> points;
  for (int i = 0; i < N; i++) if (!deleted[circles[i].id]) {
    points.emplace_back(circles[i].x / side, circles[i].y / side);
  }
  sort(begin(points), end(points));
  points.resize(unique(begin(points), end(points)) - begin(points));

  areas.clear();
  for (auto p : points) {
    areas.emplace_back(p, vector<int>());
  }
  for (int i = 0; i < N; i++) if (!deleted[circles[i].id]) {
    auto pos = lower_bound(begin(points), end(points), Point(circles[i].x / side, circles[i].y / side));
    areas[(pos - begin(points))].second.emplace_back(circles[i].id);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    x += 1e9, y += 1e9;
    circles.emplace_back(x, y, r, i);
    deleted.emplace_back(false);
    answer.emplace_back(-1);
  }

  sort(begin(circles), end(circles));
  revpos.resize(N);
  for (int i = 0; i < N; i++) {
    revpos[circles[i].id] = i;
  }  

  int lg = 30;
  Resize(lg);

  for (auto c : circles) if (!deleted[c.id]) {
    while ((1 << (lg - 1)) >= c.r) {
      Resize(--lg);
    }
    int side = 1 << lg;
    int x = c.x / side;
    int y = c.y / side;
    for (int dx = -2; dx <= 2; dx++) {
      for (int dy = -2; dy <= 2; dy++) {
        auto it = lower_bound(begin(areas), end(areas), 
                  pair<Point, vector<int>>{{x + dx, y + dy}, vector<int>()});
        if (it == end(areas) || it->first != make_pair(x + dx, y + dy)) {
          continue;
        }
        for (auto j : it->second) {
          if (Intersect(c, circles[revpos[j]]) && !deleted[j]) {
            answer[j] = c.id;
            deleted[j] = true;
          }
        }
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << answer[i] + 1 << " \n"[i + 1 == N];
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 768 KB Output is correct
22 Correct 33 ms 1088 KB Output is correct
23 Correct 34 ms 1152 KB Output is correct
24 Correct 31 ms 1132 KB Output is correct
25 Correct 34 ms 1152 KB Output is correct
26 Correct 32 ms 1084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 22548 KB Output is correct
2 Correct 260 ms 23444 KB Output is correct
3 Correct 248 ms 24852 KB Output is correct
4 Correct 208 ms 23064 KB Output is correct
5 Incorrect 968 ms 21012 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 658 ms 13816 KB Output is correct
3 Correct 2636 ms 46712 KB Output is correct
4 Correct 2661 ms 46696 KB Output is correct
5 Incorrect 2125 ms 38728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2809 ms 46552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 768 KB Output is correct
22 Correct 33 ms 1088 KB Output is correct
23 Correct 34 ms 1152 KB Output is correct
24 Correct 31 ms 1132 KB Output is correct
25 Correct 34 ms 1152 KB Output is correct
26 Correct 32 ms 1084 KB Output is correct
27 Correct 13 ms 1216 KB Output is correct
28 Correct 13 ms 1216 KB Output is correct
29 Correct 11 ms 1216 KB Output is correct
30 Correct 62 ms 1916 KB Output is correct
31 Correct 62 ms 1824 KB Output is correct
32 Correct 63 ms 1800 KB Output is correct
33 Correct 77 ms 8284 KB Output is correct
34 Correct 74 ms 8360 KB Output is correct
35 Correct 90 ms 8368 KB Output is correct
36 Correct 772 ms 14040 KB Output is correct
37 Correct 783 ms 14260 KB Output is correct
38 Correct 759 ms 14300 KB Output is correct
39 Incorrect 524 ms 11496 KB Output isn't correct
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 768 KB Output is correct
22 Correct 33 ms 1088 KB Output is correct
23 Correct 34 ms 1152 KB Output is correct
24 Correct 31 ms 1132 KB Output is correct
25 Correct 34 ms 1152 KB Output is correct
26 Correct 32 ms 1084 KB Output is correct
27 Correct 229 ms 22548 KB Output is correct
28 Correct 260 ms 23444 KB Output is correct
29 Correct 248 ms 24852 KB Output is correct
30 Correct 208 ms 23064 KB Output is correct
31 Incorrect 968 ms 21012 KB Output isn't correct
32 Halted 0 ms 0 KB -