Submission #963462

# Submission time Handle Problem Language Result Execution time Memory
963462 2024-04-15T04:21:50 Z nguyentunglam Circle selection (APIO18_circle_selection) C++17
100 / 100
1266 ms 108856 KB
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define int long long
using namespace std;

const int N = 3e5 + 10;

int n;

int x[N], y[N], r[N], dd[N];

int ans[N];

int R;

vector<int> arr[N];

vector<pair<int, int> > rrh;

int idx (int x, int y) {
  int ret = upper_bound(all(rrh), make_pair(x, y)) - rrh.begin();
  if (rrh[ret - 1].first == x && rrh[ret - 1].second == y) return ret;
  return 0;
}

void rebuild () {
  rrh.clear();
  for(int i = 1; i <= n; i++) rrh.emplace_back(x[i] / R, y[i] / R);

  sort(all(rrh));
  rrh.resize(unique(all(rrh)) - rrh.begin());

  for(int i = 1; i <= rrh.size(); i++) arr[i].clear(), dd[i] = 0;

  for(int i = 1; i <= n; i++) {
    arr[idx(x[i] / R, y[i] / R)].push_back(i);
  }
}

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n;

  for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];

  vector<pair<int, int> > order;

  for(int i = 1; i <= n; i++) order.emplace_back(r[i], -i);

  sort(all(order), greater<pair<int, int> > ());

  R = order[0].first;
  rebuild();

  for(auto &[radius, i] : order) {
    i = -i;
//    cout << i << " " << ans[i] << endl;
    if (ans[i]) continue;
    int cur = idx(x[i] / R, y[i] / R);
    if (dd[cur]) {
      R = radius;
      rebuild();
    }
    else dd[cur] = 1;

    for(int deltax = -2; deltax <= 2; deltax++) for(int deltay = -2; deltay <= 2; deltay++) {
      int pos = idx(x[i] / R + deltax, y[i] / R + deltay);
      for(auto &j : arr[pos]) if (!ans[j]) {
        if (1LL * (x[i] - x[j]) * (x[i] - x[j]) + 1LL * (y[i] - y[j]) * (y[i] - y[j]) <= 1LL * (r[i] + r[j]) * (r[i] + r[j])) {
          ans[j] = i;
        }
      }
    }
  }

  for(int i = 1; i <= n; i++) cout << ans[i] << " ";
}

Compilation message

circle_selection.cpp: In function 'void rebuild()':
circle_selection.cpp:34:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 1; i <= rrh.size(); i++) arr[i].clear(), dd[i] = 0;
      |                  ~~^~~~~~~~~~~~~
circle_selection.cpp: In function 'int32_t main()':
circle_selection.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:52:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:53:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16992 KB Output is correct
2 Correct 3 ms 17036 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 17036 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 4 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 17244 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 4 ms 17124 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 6 ms 17500 KB Output is correct
20 Correct 7 ms 17416 KB Output is correct
21 Correct 6 ms 17416 KB Output is correct
22 Correct 14 ms 17408 KB Output is correct
23 Correct 15 ms 17520 KB Output is correct
24 Correct 15 ms 17528 KB Output is correct
25 Correct 14 ms 17500 KB Output is correct
26 Correct 15 ms 17500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 45244 KB Output is correct
2 Correct 158 ms 43568 KB Output is correct
3 Correct 138 ms 44840 KB Output is correct
4 Correct 161 ms 46156 KB Output is correct
5 Correct 370 ms 48476 KB Output is correct
6 Correct 811 ms 47088 KB Output is correct
7 Correct 531 ms 49748 KB Output is correct
8 Correct 554 ms 48264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 301 ms 28660 KB Output is correct
3 Correct 1042 ms 49876 KB Output is correct
4 Correct 1147 ms 48368 KB Output is correct
5 Correct 1165 ms 51432 KB Output is correct
6 Correct 376 ms 36068 KB Output is correct
7 Correct 165 ms 26696 KB Output is correct
8 Correct 30 ms 18660 KB Output is correct
9 Correct 1210 ms 50768 KB Output is correct
10 Correct 1096 ms 51316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 834 ms 50264 KB Output is correct
2 Correct 717 ms 48928 KB Output is correct
3 Correct 281 ms 44740 KB Output is correct
4 Correct 721 ms 47660 KB Output is correct
5 Correct 749 ms 49880 KB Output is correct
6 Correct 197 ms 45612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16992 KB Output is correct
2 Correct 3 ms 17036 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 17036 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 4 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 17244 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 4 ms 17124 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 6 ms 17500 KB Output is correct
20 Correct 7 ms 17416 KB Output is correct
21 Correct 6 ms 17416 KB Output is correct
22 Correct 14 ms 17408 KB Output is correct
23 Correct 15 ms 17520 KB Output is correct
24 Correct 15 ms 17528 KB Output is correct
25 Correct 14 ms 17500 KB Output is correct
26 Correct 15 ms 17500 KB Output is correct
27 Correct 9 ms 18008 KB Output is correct
28 Correct 7 ms 17756 KB Output is correct
29 Correct 8 ms 17676 KB Output is correct
30 Correct 30 ms 18012 KB Output is correct
31 Correct 25 ms 17756 KB Output is correct
32 Correct 25 ms 18012 KB Output is correct
33 Correct 46 ms 27156 KB Output is correct
34 Correct 46 ms 27532 KB Output is correct
35 Correct 109 ms 30952 KB Output is correct
36 Correct 272 ms 28544 KB Output is correct
37 Correct 267 ms 28484 KB Output is correct
38 Correct 301 ms 28556 KB Output is correct
39 Correct 233 ms 38212 KB Output is correct
40 Correct 276 ms 38904 KB Output is correct
41 Correct 246 ms 39784 KB Output is correct
42 Correct 115 ms 27528 KB Output is correct
43 Correct 207 ms 28336 KB Output is correct
44 Correct 201 ms 28304 KB Output is correct
45 Correct 218 ms 28284 KB Output is correct
46 Correct 216 ms 28480 KB Output is correct
47 Correct 205 ms 28488 KB Output is correct
48 Correct 204 ms 28420 KB Output is correct
49 Correct 207 ms 28480 KB Output is correct
50 Correct 235 ms 28424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16992 KB Output is correct
2 Correct 3 ms 17036 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 17036 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 4 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 17244 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 4 ms 17124 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 6 ms 17500 KB Output is correct
20 Correct 7 ms 17416 KB Output is correct
21 Correct 6 ms 17416 KB Output is correct
22 Correct 14 ms 17408 KB Output is correct
23 Correct 15 ms 17520 KB Output is correct
24 Correct 15 ms 17528 KB Output is correct
25 Correct 14 ms 17500 KB Output is correct
26 Correct 15 ms 17500 KB Output is correct
27 Correct 157 ms 45244 KB Output is correct
28 Correct 158 ms 43568 KB Output is correct
29 Correct 138 ms 44840 KB Output is correct
30 Correct 161 ms 46156 KB Output is correct
31 Correct 370 ms 48476 KB Output is correct
32 Correct 811 ms 47088 KB Output is correct
33 Correct 531 ms 49748 KB Output is correct
34 Correct 554 ms 48264 KB Output is correct
35 Correct 3 ms 16988 KB Output is correct
36 Correct 301 ms 28660 KB Output is correct
37 Correct 1042 ms 49876 KB Output is correct
38 Correct 1147 ms 48368 KB Output is correct
39 Correct 1165 ms 51432 KB Output is correct
40 Correct 376 ms 36068 KB Output is correct
41 Correct 165 ms 26696 KB Output is correct
42 Correct 30 ms 18660 KB Output is correct
43 Correct 1210 ms 50768 KB Output is correct
44 Correct 1096 ms 51316 KB Output is correct
45 Correct 834 ms 50264 KB Output is correct
46 Correct 717 ms 48928 KB Output is correct
47 Correct 281 ms 44740 KB Output is correct
48 Correct 721 ms 47660 KB Output is correct
49 Correct 749 ms 49880 KB Output is correct
50 Correct 197 ms 45612 KB Output is correct
51 Correct 9 ms 18008 KB Output is correct
52 Correct 7 ms 17756 KB Output is correct
53 Correct 8 ms 17676 KB Output is correct
54 Correct 30 ms 18012 KB Output is correct
55 Correct 25 ms 17756 KB Output is correct
56 Correct 25 ms 18012 KB Output is correct
57 Correct 46 ms 27156 KB Output is correct
58 Correct 46 ms 27532 KB Output is correct
59 Correct 109 ms 30952 KB Output is correct
60 Correct 272 ms 28544 KB Output is correct
61 Correct 267 ms 28484 KB Output is correct
62 Correct 301 ms 28556 KB Output is correct
63 Correct 233 ms 38212 KB Output is correct
64 Correct 276 ms 38904 KB Output is correct
65 Correct 246 ms 39784 KB Output is correct
66 Correct 115 ms 27528 KB Output is correct
67 Correct 207 ms 28336 KB Output is correct
68 Correct 201 ms 28304 KB Output is correct
69 Correct 218 ms 28284 KB Output is correct
70 Correct 216 ms 28480 KB Output is correct
71 Correct 205 ms 28488 KB Output is correct
72 Correct 204 ms 28420 KB Output is correct
73 Correct 207 ms 28480 KB Output is correct
74 Correct 235 ms 28424 KB Output is correct
75 Correct 428 ms 60916 KB Output is correct
76 Correct 141 ms 46940 KB Output is correct
77 Correct 133 ms 46812 KB Output is correct
78 Correct 135 ms 43960 KB Output is correct
79 Correct 535 ms 59028 KB Output is correct
80 Correct 133 ms 49464 KB Output is correct
81 Correct 1061 ms 49708 KB Output is correct
82 Correct 1010 ms 49184 KB Output is correct
83 Correct 1018 ms 48924 KB Output is correct
84 Correct 1161 ms 50408 KB Output is correct
85 Correct 1022 ms 50480 KB Output is correct
86 Correct 1117 ms 50880 KB Output is correct
87 Correct 1266 ms 49576 KB Output is correct
88 Correct 875 ms 81456 KB Output is correct
89 Correct 865 ms 105024 KB Output is correct
90 Correct 824 ms 96344 KB Output is correct
91 Correct 868 ms 108856 KB Output is correct
92 Correct 855 ms 84636 KB Output is correct
93 Correct 895 ms 47696 KB Output is correct
94 Correct 952 ms 49704 KB Output is correct
95 Correct 1016 ms 47472 KB Output is correct
96 Correct 981 ms 50156 KB Output is correct
97 Correct 1128 ms 49992 KB Output is correct
98 Correct 962 ms 49320 KB Output is correct
99 Correct 910 ms 49756 KB Output is correct
100 Correct 735 ms 47892 KB Output is correct
101 Correct 1153 ms 48656 KB Output is correct
102 Correct 974 ms 46936 KB Output is correct
103 Correct 1152 ms 51220 KB Output is correct
104 Correct 893 ms 48496 KB Output is correct
105 Correct 666 ms 44696 KB Output is correct
106 Correct 701 ms 48868 KB Output is correct
107 Correct 694 ms 49680 KB Output is correct
108 Correct 698 ms 47712 KB Output is correct
109 Correct 705 ms 47808 KB Output is correct
110 Correct 678 ms 50224 KB Output is correct
111 Correct 674 ms 48092 KB Output is correct
112 Correct 663 ms 50476 KB Output is correct
113 Correct 691 ms 49088 KB Output is correct
114 Correct 680 ms 50384 KB Output is correct
115 Correct 674 ms 49772 KB Output is correct
116 Correct 649 ms 49584 KB Output is correct