Submission #399815

# Submission time Handle Problem Language Result Execution time Memory
399815 2021-05-06T16:56:51 Z my99n Circle selection (APIO18_circle_selection) C++14
12 / 100
838 ms 66680 KB
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<long long,long long> point;
 
struct A {
  long long x, y, r;
  int i;
  bool operator < (const A & o) const {
    if (r == o.r) return i < o.i;
    return r > o.r;
  }
} ori[300100], cir[300100];
 
struct X {
  long long x;
  int i, t;
  bool operator < (const X & o) const {
    if (x == o.x) return i < o.i;
    return x < o.x;
  }
};

set<X> sx;
 
int ans[300100];
 
long long dis (point i, point j) {
  long long temp = ((i.x-j.x) * (i.x-j.x)) + ((i.y-j.y) * (i.y-j.y));
  return temp;
}
 
bool intersect (A i, A j) {
  return (dis({i.x, i.y}, {j.x, j.y}) <= (i.r+j.r)*(i.r+j.r));
}

bool cover (A i, long long x, long long y) {
  return intersect(i, {x, y, 0, -1});
}
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    long long x, y, r; cin >> x >> y >> r;
    ori[i] = cir[i] = {x, y, r, i};
    sx.insert({x+r, i, 1});
    sx.insert({x-r, i, 0});
  }
  sort(cir+1, cir+1+n);

  // for (auto x : sx) {
  //   cerr << x.i << ' ' << x.t << endl;
  // }
 
  for (int i = 1; i <= n; i++) {
    int ind = cir[i].i;
    // cerr << ind << endl;
    if (ans[ind]) continue;
    auto a = sx.lower_bound({ori[ind].x, ind, -1});
    // cerr << "a " << a->x << ' ' << a->i << ' ' << a->t << endl;
    if (a != sx.begin()) {
      auto x = prev(a);
      while (x != sx.begin()) {
        // cerr  << "x " << x->x << ' ' << x->i << ' ' << x->t << endl;
        if (ans[x->i] != 0) {
          auto temp = x--;
          sx.erase(temp);
          continue;
        }
        // cerr  << "x " << x->x << ' ' << x->i << ' ' << x->t << endl;
        if (!intersect(ori[ind], ori[x->i])) break;
        // cerr << "ans " << x->i << ' ' << ind << endl;
        ans[x->i] = ind;
        auto temp = x--;
        sx.erase(temp);
      }
      if (x == sx.begin() and intersect(ori[ind], ori[x->i])) {
        if (!ans[x->i]) ans[x->i] = ind;
        // cerr << "ans " << x->i << ' ' << ind << endl;
        auto temp = x;
        sx.erase(temp);
      }
    }
    auto x = a;
    while (x != sx.end()) {
      // cerr  << "x " << x->x << ' ' << x->i << ' ' << x->t << endl;
      if (ans[x->i] != 0) {
        auto temp = x++;
        sx.erase(temp);
        continue;
      }
      // cerr  << "x " << x->x << ' ' << x->i << ' ' << x->t << endl;
      if (!intersect(ori[ind], ori[x->i])) break;
      ans[x->i] = ind;
      // cerr << "ans " << x->i << ' ' << ind << endl;
      auto temp = x++;
      sx.erase(temp);
    }
  }
 
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  } cout << endl;
  return 0;
}
/*
11 
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 687 ms 59952 KB Output is correct
2 Correct 705 ms 66680 KB Output is correct
3 Correct 727 ms 66272 KB Output is correct
4 Correct 688 ms 66628 KB Output is correct
5 Correct 648 ms 64324 KB Output is correct
6 Correct 683 ms 64484 KB Output is correct
7 Correct 646 ms 64556 KB Output is correct
8 Correct 661 ms 64388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 838 ms 58340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -