Submission #966742

# Submission time Handle Problem Language Result Execution time Memory
966742 2024-04-20T09:31:26 Z Soumya1 Circle selection (APIO18_circle_selection) C++17
42 / 100
3000 ms 35700 KB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 5;
int x[mxN], y[mxN], r[mxN], ans[mxN];
bool intersect(int a, int b) {
  return 1LL * (x[a] - x[b]) * (x[a] - x[b]) + 1LL * (y[a] - y[b]) * (y[a] - y[b]) <= 1LL * (r[a] + r[b]) * (r[a] + r[b]);
}
int block;
vector<int> all[mxN];
vector<pair<int, int>> vv;
int n;
int get(pair<int, int> p) {
  auto it = lower_bound(vv.begin(), vv.end(), p);
  if (it != vv.end() && *it == p) return it - vv.begin();
  return -1;
}
void scale() {
  vv.clear();
  for (int i = 0; i < n; i++) all[i].clear();
  for (int i = 0; i < n; i++) {
    if (ans[i]) continue;
    vv.push_back({x[i] / block, y[i] / block});
  }
  sort(vv.begin(), vv.end());
  vv.erase(unique(vv.begin(), vv.end()), vv.end());
  for (int i = 0; i < n; i++) {
    if (ans[i]) continue;
    all[get({x[i] / block, y[i] / block})].push_back(i);
  }
}
void testCase() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    if (r[i] != r[j]) return r[i] > r[j];
    return i < j;
  });
  block = r[ord[0]];
  scale();
  for (int i : ord) {
    if (ans[i]) continue;
    if (2 * r[i] < block) {
      block = 2 * r[i];
      scale();
    }
    for (int xx = x[i] / block - 2; xx <= x[i] / block + 2; xx++) {
      for (int yy = y[i] / block - 2; yy <= y[i] / block + 2; yy++) {
        auto id = get({xx, yy});
        if (id == -1) continue;
        for (int j = 0; j < all[id].size(); ) {
          if (intersect(i, all[id][j])) {
            ans[all[id][j]] = i + 1;
            swap(all[id][j], all[id].back());
            all[id].pop_back();
          } else {
            j++;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}

Compilation message

circle_selection.cpp: In function 'void testCase()':
circle_selection.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j = 0; j < all[id].size(); ) {
      |                         ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10896 KB Output is correct
13 Correct 3 ms 10844 KB Output is correct
14 Correct 3 ms 10852 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 6 ms 11100 KB Output is correct
20 Correct 4 ms 11100 KB Output is correct
21 Correct 4 ms 11100 KB Output is correct
22 Correct 404 ms 11248 KB Output is correct
23 Correct 342 ms 11348 KB Output is correct
24 Correct 425 ms 11100 KB Output is correct
25 Correct 328 ms 11240 KB Output is correct
26 Correct 401 ms 11096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 27256 KB Output is correct
2 Correct 133 ms 27384 KB Output is correct
3 Correct 130 ms 27704 KB Output is correct
4 Correct 123 ms 27520 KB Output is correct
5 Correct 206 ms 24084 KB Output is correct
6 Correct 629 ms 27276 KB Output is correct
7 Correct 319 ms 25188 KB Output is correct
8 Correct 354 ms 25032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11092 KB Output is correct
2 Execution timed out 3046 ms 18280 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 770 ms 35700 KB Output is correct
2 Correct 650 ms 34628 KB Output is correct
3 Correct 235 ms 28356 KB Output is correct
4 Correct 680 ms 35464 KB Output is correct
5 Correct 653 ms 34728 KB Output is correct
6 Correct 170 ms 28708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10896 KB Output is correct
13 Correct 3 ms 10844 KB Output is correct
14 Correct 3 ms 10852 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 6 ms 11100 KB Output is correct
20 Correct 4 ms 11100 KB Output is correct
21 Correct 4 ms 11100 KB Output is correct
22 Correct 404 ms 11248 KB Output is correct
23 Correct 342 ms 11348 KB Output is correct
24 Correct 425 ms 11100 KB Output is correct
25 Correct 328 ms 11240 KB Output is correct
26 Correct 401 ms 11096 KB Output is correct
27 Correct 8 ms 11608 KB Output is correct
28 Correct 6 ms 11356 KB Output is correct
29 Correct 6 ms 11356 KB Output is correct
30 Correct 1606 ms 11616 KB Output is correct
31 Correct 1562 ms 11620 KB Output is correct
32 Correct 1416 ms 11628 KB Output is correct
33 Correct 45 ms 16816 KB Output is correct
34 Correct 46 ms 16848 KB Output is correct
35 Correct 76 ms 16572 KB Output is correct
36 Execution timed out 3040 ms 18000 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10896 KB Output is correct
13 Correct 3 ms 10844 KB Output is correct
14 Correct 3 ms 10852 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 6 ms 11100 KB Output is correct
20 Correct 4 ms 11100 KB Output is correct
21 Correct 4 ms 11100 KB Output is correct
22 Correct 404 ms 11248 KB Output is correct
23 Correct 342 ms 11348 KB Output is correct
24 Correct 425 ms 11100 KB Output is correct
25 Correct 328 ms 11240 KB Output is correct
26 Correct 401 ms 11096 KB Output is correct
27 Correct 132 ms 27256 KB Output is correct
28 Correct 133 ms 27384 KB Output is correct
29 Correct 130 ms 27704 KB Output is correct
30 Correct 123 ms 27520 KB Output is correct
31 Correct 206 ms 24084 KB Output is correct
32 Correct 629 ms 27276 KB Output is correct
33 Correct 319 ms 25188 KB Output is correct
34 Correct 354 ms 25032 KB Output is correct
35 Correct 3 ms 11092 KB Output is correct
36 Execution timed out 3046 ms 18280 KB Time limit exceeded
37 Halted 0 ms 0 KB -