Submission #539239

# Submission time Handle Problem Language Result Execution time Memory
539239 2022-03-18T15:27:03 Z cadmiumsky Circle selection (APIO18_circle_selection) C++14
100 / 100
1732 ms 97508 KB
#include <bits/stdc++.h>
#warning inca un tle si bagi tangenta (chiar daca nu e safe <(._ .)>)
using namespace std;
using ll = long long;

namespace Cercus {
  unordered_map<int, unordered_map<int, vector<int> > > cont;
  int lastr = 2e9 + 5;
  vector<tuple<int, int, int> > v;
  vector<int> sorted, elim;
  int xx[2], yy[2], rr[2];
  ll p2(ll x) { return x * x; }
  bool check(int i, int j) {
    tie(rr[0], xx[0], yy[0]) = v[i];
    tie(rr[1], xx[1], yy[1]) = v[j];
    return p2(xx[0] - xx[1]) + p2(yy[0] - yy[1]) <= p2(rr[0] + rr[1]);
  }
  void redocontainer(int nr) {
    cont.erase(cont.begin(), cont.end());
    lastr = nr;
    for(int i = 0, x, y, r; i < v.size(); i++) {
      if(elim[i] == -1) {
        tie(r, x, y) = v[i];
        cont[x / (2 * nr)][y / (2 * nr)].push_back(i);
      }
    }
  }
  void gothrough(int ind) {
    if(elim[ind] != -1)
      return;
    int x, y, r;
    tie(r, x, y) = v[ind];
    if(r <= lastr / 2)
      redocontainer(r);
    x /= 2 * lastr;
    y /= 2 * lastr;
    //cerr << "--" << lastr << "--\n";
    for(int i = x - 1; i <= x + 1; i++) {
      if(cont.find(i) == cont.end())
        continue;
      for(int j = y - 1; j <= y + 1; j++) {
        if(cont[i].find(j) == cont[i].end())
          continue;
        for(int ptr = 0, z; ptr < cont[i][j].size(); ptr++) {
          z = cont[i][j][ptr];
          //cerr << ind + 1<< "--> " << z + 1 << ' ';
          if(check(z, ind)) {
            //cerr << "YES";
            elim[z] = ind;
            swap(cont[i][j].back(), cont[i][j][ptr]);
            cont[i][j].pop_back();
            ptr--;
          }
          //cerr << '\n';
        }
      }
    }
  }
  void read() {
    int n;
    cin >> n;
    v.resize(n);
    sorted.resize(n);
    elim.resize(n);
    for(auto &[r, x, y] : v)
      cin >> x >> y >> r;
    for(int i = 0; i < n; i++)
      sorted[i] = i, elim[i] = -1;
    sort(sorted.begin(), sorted.end(), [&](auto x, auto y) { return get<0>(v[x]) > get<0>(v[y]) || (get<0>(v[x]) == get<0>(v[y]) && x < y);});
  }
  void startelim() {
    for(auto z : sorted)
      gothrough(z);
  }
  void print() {
    for(auto x : elim)
      cout << x + 1 << ' ';
    cout << '\n';
    return;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Cercus::read();
  Cercus::startelim();
  Cercus::print();
}

Compilation message

circle_selection.cpp:2:2: warning: #warning inca un tle si bagi tangenta (chiar daca nu e safe <(._ .)>) [-Wcpp]
    2 | #warning inca un tle si bagi tangenta (chiar daca nu e safe <(._ .)>)
      |  ^~~~~~~
circle_selection.cpp: In function 'void Cercus::redocontainer(int)':
circle_selection.cpp:21:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i = 0, x, y, r; i < v.size(); i++) {
      |                             ~~^~~~~~~~~~
circle_selection.cpp: In function 'void Cercus::gothrough(int)':
circle_selection.cpp:44:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int ptr = 0, z; ptr < cont[i][j].size(); ptr++) {
      |                             ~~~~^~~~~~~~~~~~~~~~~~~
circle_selection.cpp: In function 'void Cercus::read()':
circle_selection.cpp:65:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   65 |     for(auto &[r, x, y] : v)
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 2 ms 368 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 4 ms 656 KB Output is correct
21 Correct 4 ms 568 KB Output is correct
22 Correct 8 ms 1316 KB Output is correct
23 Correct 10 ms 980 KB Output is correct
24 Correct 11 ms 1364 KB Output is correct
25 Correct 10 ms 1800 KB Output is correct
26 Correct 10 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 8868 KB Output is correct
2 Correct 208 ms 8876 KB Output is correct
3 Correct 189 ms 9756 KB Output is correct
4 Correct 212 ms 8868 KB Output is correct
5 Correct 235 ms 11332 KB Output is correct
6 Correct 657 ms 33952 KB Output is correct
7 Correct 269 ms 13236 KB Output is correct
8 Correct 340 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 379 ms 12796 KB Output is correct
3 Correct 1732 ms 36944 KB Output is correct
4 Correct 1607 ms 37004 KB Output is correct
5 Correct 1397 ms 27596 KB Output is correct
6 Correct 460 ms 13908 KB Output is correct
7 Correct 160 ms 8084 KB Output is correct
8 Correct 31 ms 3176 KB Output is correct
9 Correct 1498 ms 34824 KB Output is correct
10 Correct 866 ms 25640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 843 ms 40288 KB Output is correct
2 Correct 662 ms 91004 KB Output is correct
3 Correct 230 ms 12304 KB Output is correct
4 Correct 600 ms 83128 KB Output is correct
5 Correct 677 ms 87416 KB Output is correct
6 Correct 246 ms 10664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 2 ms 368 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 4 ms 656 KB Output is correct
21 Correct 4 ms 568 KB Output is correct
22 Correct 8 ms 1316 KB Output is correct
23 Correct 10 ms 980 KB Output is correct
24 Correct 11 ms 1364 KB Output is correct
25 Correct 10 ms 1800 KB Output is correct
26 Correct 10 ms 1520 KB Output is correct
27 Correct 9 ms 836 KB Output is correct
28 Correct 9 ms 980 KB Output is correct
29 Correct 8 ms 852 KB Output is correct
30 Correct 20 ms 1748 KB Output is correct
31 Correct 16 ms 2228 KB Output is correct
32 Correct 19 ms 2380 KB Output is correct
33 Correct 64 ms 3808 KB Output is correct
34 Correct 63 ms 3908 KB Output is correct
35 Correct 69 ms 3544 KB Output is correct
36 Correct 350 ms 15496 KB Output is correct
37 Correct 382 ms 15100 KB Output is correct
38 Correct 393 ms 13520 KB Output is correct
39 Correct 450 ms 8272 KB Output is correct
40 Correct 465 ms 8960 KB Output is correct
41 Correct 445 ms 8888 KB Output is correct
42 Correct 122 ms 6772 KB Output is correct
43 Correct 210 ms 31888 KB Output is correct
44 Correct 248 ms 31944 KB Output is correct
45 Correct 230 ms 31832 KB Output is correct
46 Correct 229 ms 31860 KB Output is correct
47 Correct 252 ms 31824 KB Output is correct
48 Correct 220 ms 31844 KB Output is correct
49 Correct 228 ms 31828 KB Output is correct
50 Correct 244 ms 31828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 2 ms 368 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 4 ms 656 KB Output is correct
21 Correct 4 ms 568 KB Output is correct
22 Correct 8 ms 1316 KB Output is correct
23 Correct 10 ms 980 KB Output is correct
24 Correct 11 ms 1364 KB Output is correct
25 Correct 10 ms 1800 KB Output is correct
26 Correct 10 ms 1520 KB Output is correct
27 Correct 217 ms 8868 KB Output is correct
28 Correct 208 ms 8876 KB Output is correct
29 Correct 189 ms 9756 KB Output is correct
30 Correct 212 ms 8868 KB Output is correct
31 Correct 235 ms 11332 KB Output is correct
32 Correct 657 ms 33952 KB Output is correct
33 Correct 269 ms 13236 KB Output is correct
34 Correct 340 ms 16748 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 379 ms 12796 KB Output is correct
37 Correct 1732 ms 36944 KB Output is correct
38 Correct 1607 ms 37004 KB Output is correct
39 Correct 1397 ms 27596 KB Output is correct
40 Correct 460 ms 13908 KB Output is correct
41 Correct 160 ms 8084 KB Output is correct
42 Correct 31 ms 3176 KB Output is correct
43 Correct 1498 ms 34824 KB Output is correct
44 Correct 866 ms 25640 KB Output is correct
45 Correct 843 ms 40288 KB Output is correct
46 Correct 662 ms 91004 KB Output is correct
47 Correct 230 ms 12304 KB Output is correct
48 Correct 600 ms 83128 KB Output is correct
49 Correct 677 ms 87416 KB Output is correct
50 Correct 246 ms 10664 KB Output is correct
51 Correct 9 ms 836 KB Output is correct
52 Correct 9 ms 980 KB Output is correct
53 Correct 8 ms 852 KB Output is correct
54 Correct 20 ms 1748 KB Output is correct
55 Correct 16 ms 2228 KB Output is correct
56 Correct 19 ms 2380 KB Output is correct
57 Correct 64 ms 3808 KB Output is correct
58 Correct 63 ms 3908 KB Output is correct
59 Correct 69 ms 3544 KB Output is correct
60 Correct 350 ms 15496 KB Output is correct
61 Correct 382 ms 15100 KB Output is correct
62 Correct 393 ms 13520 KB Output is correct
63 Correct 450 ms 8272 KB Output is correct
64 Correct 465 ms 8960 KB Output is correct
65 Correct 445 ms 8888 KB Output is correct
66 Correct 122 ms 6772 KB Output is correct
67 Correct 210 ms 31888 KB Output is correct
68 Correct 248 ms 31944 KB Output is correct
69 Correct 230 ms 31832 KB Output is correct
70 Correct 229 ms 31860 KB Output is correct
71 Correct 252 ms 31824 KB Output is correct
72 Correct 220 ms 31844 KB Output is correct
73 Correct 228 ms 31828 KB Output is correct
74 Correct 244 ms 31828 KB Output is correct
75 Correct 225 ms 17716 KB Output is correct
76 Correct 252 ms 17216 KB Output is correct
77 Correct 240 ms 18628 KB Output is correct
78 Correct 235 ms 18276 KB Output is correct
79 Correct 275 ms 17052 KB Output is correct
80 Correct 215 ms 18332 KB Output is correct
81 Correct 1644 ms 44432 KB Output is correct
82 Correct 1409 ms 45916 KB Output is correct
83 Correct 1185 ms 45796 KB Output is correct
84 Correct 1306 ms 43956 KB Output is correct
85 Correct 1464 ms 45092 KB Output is correct
86 Correct 1502 ms 46092 KB Output is correct
87 Correct 1194 ms 40904 KB Output is correct
88 Correct 1572 ms 26696 KB Output is correct
89 Correct 1541 ms 26692 KB Output is correct
90 Correct 1593 ms 26664 KB Output is correct
91 Correct 1504 ms 26696 KB Output is correct
92 Correct 1575 ms 26676 KB Output is correct
93 Correct 1086 ms 96068 KB Output is correct
94 Correct 863 ms 39380 KB Output is correct
95 Correct 1014 ms 96568 KB Output is correct
96 Correct 1209 ms 93088 KB Output is correct
97 Correct 1131 ms 41060 KB Output is correct
98 Correct 732 ms 37220 KB Output is correct
99 Correct 998 ms 96848 KB Output is correct
100 Correct 891 ms 97508 KB Output is correct
101 Correct 823 ms 32716 KB Output is correct
102 Correct 1028 ms 91716 KB Output is correct
103 Correct 860 ms 38900 KB Output is correct
104 Correct 1033 ms 96824 KB Output is correct
105 Correct 373 ms 20128 KB Output is correct
106 Correct 686 ms 73796 KB Output is correct
107 Correct 690 ms 73812 KB Output is correct
108 Correct 728 ms 73832 KB Output is correct
109 Correct 672 ms 73812 KB Output is correct
110 Correct 702 ms 73744 KB Output is correct
111 Correct 691 ms 73808 KB Output is correct
112 Correct 667 ms 73676 KB Output is correct
113 Correct 669 ms 73584 KB Output is correct
114 Correct 675 ms 73596 KB Output is correct
115 Correct 671 ms 73904 KB Output is correct
116 Correct 604 ms 87608 KB Output is correct