Submission #316904

# Submission time Handle Problem Language Result Execution time Memory
316904 2020-10-28T14:29:16 Z casperwang Circle selection (APIO18_circle_selection) C++14
15 / 100
540 ms 22028 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define ppi pair<pii,int>
#define ff first
#define ss second
using namespace std;

const int MAXN = 300000;

struct Cir{
  int x, y, r, id;
  Cir() {}
  Cir(int _x, int _y, int _r, int _id) {
    x = _x, y = _y, r = _r, id = _id;
  }
};

bool intersect(const Cir &a, const Cir &b) {
  return (ll)(a.x-b.x)*(a.x-b.x)+(ll)(a.y-b.y)*(a.y-b.y) <= (ll)(a.r+b.r)*(a.r+b.r);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector <Cir> cir, tmp;
  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    cir.pb(Cir(x, y, r, i+1));
  }
  sort(cir.begin(), cir.end(), [](const Cir a, const Cir b){
      return a.r != b.r ? a.r > b.r : a.id < b.id;
      });
  int now_r = cir[0].r+1;
  vector <int> ans(n+1);
  while (cir.size()) {
    vector <ppi> arr;
    for (int i = 0; i < cir.size(); i++)
      arr.pb(ppi(pii(cir[i].x / now_r, cir[i].y / now_r), i));
    sort(arr.begin(), arr.end());
    for (Cir C : cir) {
      if (ans[C.id]) continue;
      if (C.r < now_r / 2) break;
      int X = C.x / now_r, Y = C.y / now_r;
      ppi grid;
      grid.ss = 0;
      grid.ff.ss = Y-2;
      for (int i = X-2; i <= X+2; i++) {
        grid.ff.ff = i;
        int p = lower_bound(arr.begin(), arr.end(), grid) - arr.begin();
        if (p == arr.size() || arr[p].ff.ff != i) continue;
        while (p < arr.size() && arr[p].ff.ff == i && arr[p].ff.ss <= Y+2) {
          if (intersect(C, cir[arr[p].ss]))
            ans[cir[arr[p].ss].id] = C.id;
          p++;
        }
      }
    }
    arr.clear();
    for (Cir C : cir)
      if (!ans[C.id]) tmp.pb(C);
    cir = tmp;
    tmp.clear();
    now_r /= 2;
  }
  for (int i = 1; i <= n; i++)
    cout << ans[i] << " \n"[i==n];
  return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Cir>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < cir.size(); i++)
      |                     ~~^~~~~~~~~~~~
circle_selection.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if (p == arr.size() || arr[p].ff.ff != i) continue;
      |             ~~^~~~~~~~~~~~~
circle_selection.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         while (p < arr.size() && arr[p].ff.ff == i && arr[p].ff.ss <= Y+2) {
      |                ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 185 ms 16084 KB Output is correct
2 Incorrect 201 ms 15840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 153 ms 5328 KB Output is correct
3 Correct 510 ms 16424 KB Output is correct
4 Correct 524 ms 16408 KB Output is correct
5 Correct 481 ms 18876 KB Output is correct
6 Correct 210 ms 9644 KB Output is correct
7 Correct 100 ms 4764 KB Output is correct
8 Correct 18 ms 1276 KB Output is correct
9 Correct 540 ms 19232 KB Output is correct
10 Correct 476 ms 22028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 439 ms 15832 KB Output is correct
2 Correct 378 ms 15952 KB Output is correct
3 Incorrect 286 ms 16016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -