답안 #966724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966724 2024-04-20T09:06:21 Z Soumya1 원 고르기 (APIO18_circle_selection) C++17
42 / 100
3000 ms 36292 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;
        auto &v = all[id];
        for (int j = 0; j < v.size(); ) {
          if (intersect(i, v[j])) {
            ans[v[j]] = i + 1;
            swap(v[j], v.back());
            v.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:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = 0; j < v.size(); ) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 3 ms 10860 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 10840 KB Output is correct
8 Correct 2 ms 10884 KB Output is correct
9 Correct 3 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 3 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 3 ms 10844 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 5 ms 11100 KB Output is correct
20 Correct 4 ms 11100 KB Output is correct
21 Correct 4 ms 11104 KB Output is correct
22 Correct 410 ms 11264 KB Output is correct
23 Correct 363 ms 11364 KB Output is correct
24 Correct 430 ms 11100 KB Output is correct
25 Correct 337 ms 11252 KB Output is correct
26 Correct 404 ms 11100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 27764 KB Output is correct
2 Correct 150 ms 27356 KB Output is correct
3 Correct 134 ms 27516 KB Output is correct
4 Correct 165 ms 28720 KB Output is correct
5 Correct 222 ms 25148 KB Output is correct
6 Correct 682 ms 27672 KB Output is correct
7 Correct 333 ms 25064 KB Output is correct
8 Correct 383 ms 26212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Execution timed out 3058 ms 18168 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 778 ms 30744 KB Output is correct
2 Correct 664 ms 34148 KB Output is correct
3 Correct 235 ms 29636 KB Output is correct
4 Correct 701 ms 34940 KB Output is correct
5 Correct 669 ms 36292 KB Output is correct
6 Correct 178 ms 28296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 3 ms 10860 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 10840 KB Output is correct
8 Correct 2 ms 10884 KB Output is correct
9 Correct 3 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 3 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 3 ms 10844 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 5 ms 11100 KB Output is correct
20 Correct 4 ms 11100 KB Output is correct
21 Correct 4 ms 11104 KB Output is correct
22 Correct 410 ms 11264 KB Output is correct
23 Correct 363 ms 11364 KB Output is correct
24 Correct 430 ms 11100 KB Output is correct
25 Correct 337 ms 11252 KB Output is correct
26 Correct 404 ms 11100 KB Output is correct
27 Correct 6 ms 11100 KB Output is correct
28 Correct 6 ms 11100 KB Output is correct
29 Correct 6 ms 11100 KB Output is correct
30 Correct 1622 ms 11360 KB Output is correct
31 Correct 1564 ms 11604 KB Output is correct
32 Correct 1400 ms 11360 KB Output is correct
33 Correct 45 ms 13704 KB Output is correct
34 Correct 44 ms 13772 KB Output is correct
35 Correct 65 ms 13664 KB Output is correct
36 Execution timed out 3050 ms 15404 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 3 ms 10860 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 10840 KB Output is correct
8 Correct 2 ms 10884 KB Output is correct
9 Correct 3 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 3 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 3 ms 10844 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 5 ms 11100 KB Output is correct
20 Correct 4 ms 11100 KB Output is correct
21 Correct 4 ms 11104 KB Output is correct
22 Correct 410 ms 11264 KB Output is correct
23 Correct 363 ms 11364 KB Output is correct
24 Correct 430 ms 11100 KB Output is correct
25 Correct 337 ms 11252 KB Output is correct
26 Correct 404 ms 11100 KB Output is correct
27 Correct 134 ms 27764 KB Output is correct
28 Correct 150 ms 27356 KB Output is correct
29 Correct 134 ms 27516 KB Output is correct
30 Correct 165 ms 28720 KB Output is correct
31 Correct 222 ms 25148 KB Output is correct
32 Correct 682 ms 27672 KB Output is correct
33 Correct 333 ms 25064 KB Output is correct
34 Correct 383 ms 26212 KB Output is correct
35 Correct 2 ms 10840 KB Output is correct
36 Execution timed out 3058 ms 18168 KB Time limit exceeded
37 Halted 0 ms 0 KB -