답안 #658758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658758 2022-11-14T20:35:51 Z 600Mihnea 원 고르기 (APIO18_circle_selection) C++17
100 / 100
2871 ms 71612 KB
bool home = 0;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int) 3e5 + 7;
const int INF = (int) 1e9 + 7;
int n;

struct Circle {
  int x;
  int y;
  int r;
};

bool doIntersect(Circle a, Circle b) {
  /// dist <= a.r + b.r
  /// dist ^  2 <= (a.r + b.r) ^ 2
  return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y) <= 1LL * (a.r + b.r) * (a.r + b.r);
}


Circle circles[N];
int ret[N];

map<pair<int, int>, set<int>> guysAtPosition;


bool cmp(int i, int j) {
  if (circles[i].r == circles[j].r) {
    return i < j;
  } else {
    return circles[i].r > circles[j].r;
  }
}
set<int, decltype(cmp)*> s(cmp);

int r_divide_glob;

void place(int r_divide, set<int, decltype(cmp)*>& s) {
  r_divide_glob = r_divide;
  guysAtPosition.clear();
  for (auto &i : s) {
    guysAtPosition[{circles[i].x / r_divide, circles[i].y / r_divide}].insert(i);
  }
}

void elim(int i, set<int, decltype(cmp)*>& s) {
  int x = circles[i].x / r_divide_glob, y = circles[i].y / r_divide_glob;
  for (int x2 = x - 2; x2 <= x + 2; x2++) {
    for (int y2 = y - 2; y2 <= y + 2; y2++) {
      pair<int, int> it = {x2, y2};
      if (!guysAtPosition.count(it)) {
        continue;
      }
      vector<int> dl;
      for (auto &j : guysAtPosition[it]) {
        if (doIntersect(circles[i], circles[j])) {
          ret[j] = i;
          s.erase(j);
          dl.push_back(j);
        }
      }
      for (auto &j : dl) {
        guysAtPosition[it].erase(j);
      }
    }
  }
}

int main() {
  if (home == 0) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  } else {
    freopen ("input.txt", "r", stdin);
  }

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> circles[i].x >> circles[i].y >> circles[i].r;
    circles[i].x += INF;
    circles[i].y += INF;
  }

  for (int i = 1; i <= n; i++) {
    s.insert(i);
  }
  int max_radius = circles[1].r;
  for (int i = 2; i <= n; i++) {
    max_radius = max(max_radius, circles[i].r);
  }
  place(max_radius, s);
  while (!s.empty()) {
    int i = *s.begin();
    if (circles[i].r <= max_radius / 2) {
      max_radius = circles[i].r;
      place(max_radius, s);
    }
    elim(i, s);
  }

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

  return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:78:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     freopen ("input.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 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 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 960 KB Output is correct
20 Correct 6 ms 1040 KB Output is correct
21 Correct 6 ms 980 KB Output is correct
22 Correct 14 ms 1488 KB Output is correct
23 Correct 15 ms 1476 KB Output is correct
24 Correct 13 ms 1492 KB Output is correct
25 Correct 13 ms 1472 KB Output is correct
26 Correct 13 ms 1480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 829 ms 36292 KB Output is correct
2 Correct 886 ms 39132 KB Output is correct
3 Correct 865 ms 38340 KB Output is correct
4 Correct 824 ms 38720 KB Output is correct
5 Correct 813 ms 38892 KB Output is correct
6 Correct 1179 ms 52108 KB Output is correct
7 Correct 851 ms 40028 KB Output is correct
8 Correct 915 ms 42424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 559 ms 23952 KB Output is correct
3 Correct 2235 ms 66592 KB Output is correct
4 Correct 2233 ms 71428 KB Output is correct
5 Correct 2339 ms 65180 KB Output is correct
6 Correct 911 ms 33452 KB Output is correct
7 Correct 359 ms 17928 KB Output is correct
8 Correct 41 ms 3956 KB Output is correct
9 Correct 2541 ms 70628 KB Output is correct
10 Correct 2256 ms 64472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1624 ms 63432 KB Output is correct
2 Correct 1192 ms 70580 KB Output is correct
3 Correct 926 ms 51240 KB Output is correct
4 Correct 1252 ms 70764 KB Output is correct
5 Correct 1260 ms 71036 KB Output is correct
6 Correct 775 ms 44524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 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 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 960 KB Output is correct
20 Correct 6 ms 1040 KB Output is correct
21 Correct 6 ms 980 KB Output is correct
22 Correct 14 ms 1488 KB Output is correct
23 Correct 15 ms 1476 KB Output is correct
24 Correct 13 ms 1492 KB Output is correct
25 Correct 13 ms 1472 KB Output is correct
26 Correct 13 ms 1480 KB Output is correct
27 Correct 11 ms 1448 KB Output is correct
28 Correct 11 ms 1492 KB Output is correct
29 Correct 11 ms 1492 KB Output is correct
30 Correct 31 ms 2360 KB Output is correct
31 Correct 33 ms 2412 KB Output is correct
32 Correct 32 ms 2352 KB Output is correct
33 Correct 187 ms 12004 KB Output is correct
34 Correct 178 ms 11992 KB Output is correct
35 Correct 197 ms 11968 KB Output is correct
36 Correct 478 ms 21268 KB Output is correct
37 Correct 511 ms 21184 KB Output is correct
38 Correct 544 ms 21188 KB Output is correct
39 Correct 726 ms 19932 KB Output is correct
40 Correct 720 ms 20988 KB Output is correct
41 Correct 695 ms 20872 KB Output is correct
42 Correct 388 ms 22776 KB Output is correct
43 Correct 339 ms 23576 KB Output is correct
44 Correct 336 ms 23580 KB Output is correct
45 Correct 400 ms 23572 KB Output is correct
46 Correct 336 ms 23628 KB Output is correct
47 Correct 327 ms 23656 KB Output is correct
48 Correct 338 ms 23572 KB Output is correct
49 Correct 350 ms 23584 KB Output is correct
50 Correct 334 ms 23584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 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 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 960 KB Output is correct
20 Correct 6 ms 1040 KB Output is correct
21 Correct 6 ms 980 KB Output is correct
22 Correct 14 ms 1488 KB Output is correct
23 Correct 15 ms 1476 KB Output is correct
24 Correct 13 ms 1492 KB Output is correct
25 Correct 13 ms 1472 KB Output is correct
26 Correct 13 ms 1480 KB Output is correct
27 Correct 829 ms 36292 KB Output is correct
28 Correct 886 ms 39132 KB Output is correct
29 Correct 865 ms 38340 KB Output is correct
30 Correct 824 ms 38720 KB Output is correct
31 Correct 813 ms 38892 KB Output is correct
32 Correct 1179 ms 52108 KB Output is correct
33 Correct 851 ms 40028 KB Output is correct
34 Correct 915 ms 42424 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 559 ms 23952 KB Output is correct
37 Correct 2235 ms 66592 KB Output is correct
38 Correct 2233 ms 71428 KB Output is correct
39 Correct 2339 ms 65180 KB Output is correct
40 Correct 911 ms 33452 KB Output is correct
41 Correct 359 ms 17928 KB Output is correct
42 Correct 41 ms 3956 KB Output is correct
43 Correct 2541 ms 70628 KB Output is correct
44 Correct 2256 ms 64472 KB Output is correct
45 Correct 1624 ms 63432 KB Output is correct
46 Correct 1192 ms 70580 KB Output is correct
47 Correct 926 ms 51240 KB Output is correct
48 Correct 1252 ms 70764 KB Output is correct
49 Correct 1260 ms 71036 KB Output is correct
50 Correct 775 ms 44524 KB Output is correct
51 Correct 11 ms 1448 KB Output is correct
52 Correct 11 ms 1492 KB Output is correct
53 Correct 11 ms 1492 KB Output is correct
54 Correct 31 ms 2360 KB Output is correct
55 Correct 33 ms 2412 KB Output is correct
56 Correct 32 ms 2352 KB Output is correct
57 Correct 187 ms 12004 KB Output is correct
58 Correct 178 ms 11992 KB Output is correct
59 Correct 197 ms 11968 KB Output is correct
60 Correct 478 ms 21268 KB Output is correct
61 Correct 511 ms 21184 KB Output is correct
62 Correct 544 ms 21188 KB Output is correct
63 Correct 726 ms 19932 KB Output is correct
64 Correct 720 ms 20988 KB Output is correct
65 Correct 695 ms 20872 KB Output is correct
66 Correct 388 ms 22776 KB Output is correct
67 Correct 339 ms 23576 KB Output is correct
68 Correct 336 ms 23580 KB Output is correct
69 Correct 400 ms 23572 KB Output is correct
70 Correct 336 ms 23628 KB Output is correct
71 Correct 327 ms 23656 KB Output is correct
72 Correct 338 ms 23572 KB Output is correct
73 Correct 350 ms 23584 KB Output is correct
74 Correct 334 ms 23584 KB Output is correct
75 Correct 874 ms 44696 KB Output is correct
76 Correct 867 ms 44228 KB Output is correct
77 Correct 786 ms 44144 KB Output is correct
78 Correct 783 ms 44044 KB Output is correct
79 Correct 952 ms 43980 KB Output is correct
80 Correct 839 ms 44496 KB Output is correct
81 Correct 2123 ms 71328 KB Output is correct
82 Correct 2029 ms 71156 KB Output is correct
83 Correct 2059 ms 71324 KB Output is correct
84 Correct 2244 ms 71612 KB Output is correct
85 Correct 2108 ms 71244 KB Output is correct
86 Correct 2132 ms 71372 KB Output is correct
87 Correct 2437 ms 71168 KB Output is correct
88 Correct 2828 ms 62444 KB Output is correct
89 Correct 2753 ms 62412 KB Output is correct
90 Correct 2836 ms 62500 KB Output is correct
91 Correct 2675 ms 62448 KB Output is correct
92 Correct 2871 ms 62396 KB Output is correct
93 Correct 1538 ms 70176 KB Output is correct
94 Correct 1777 ms 70448 KB Output is correct
95 Correct 1510 ms 70172 KB Output is correct
96 Correct 1601 ms 70208 KB Output is correct
97 Correct 2238 ms 70084 KB Output is correct
98 Correct 1289 ms 60316 KB Output is correct
99 Correct 1591 ms 70344 KB Output is correct
100 Correct 1434 ms 70112 KB Output is correct
101 Correct 1569 ms 64688 KB Output is correct
102 Correct 1567 ms 69932 KB Output is correct
103 Correct 2250 ms 69872 KB Output is correct
104 Correct 1583 ms 70044 KB Output is correct
105 Correct 1374 ms 67916 KB Output is correct
106 Correct 1224 ms 69208 KB Output is correct
107 Correct 1219 ms 69208 KB Output is correct
108 Correct 1206 ms 69256 KB Output is correct
109 Correct 1255 ms 69288 KB Output is correct
110 Correct 1216 ms 69196 KB Output is correct
111 Correct 1220 ms 69328 KB Output is correct
112 Correct 1213 ms 69192 KB Output is correct
113 Correct 1205 ms 69200 KB Output is correct
114 Correct 1217 ms 69192 KB Output is correct
115 Correct 1197 ms 69196 KB Output is correct
116 Correct 1177 ms 69280 KB Output is correct