Submission #265061

# Submission time Handle Problem Language Result Execution time Memory
265061 2020-08-14T12:44:40 Z extraterrestrial Circle selection (APIO18_circle_selection) C++14
7 / 100
3000 ms 72828 KB
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back  
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll    

const int N = 3e5 + 10;
int x[N], y[N], r[N], ans[N];

bool inter(int id1, int id2) {
  return (x[id1] - x[id2]) * (x[id1] - x[id2]) + (y[id1] - y[id2]) * (y[id1] - y[id2]) <= (r[id1] + r[id2]) * (r[id1] + r[id2]); 
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
  int n;
  cin >> n;
  bool group2 = true;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
    if (y[i] != 0) {
      group2 = false;
    }
  }
  if (!group2) {
    vector<bool> used(n);
    int cnt = 0;
    while (cnt < n) {
      pair<int, int> best = {1e9, 1e9};
      for (int i = 0; i < n; i++) {
        if (!used[i]) {
          best = min(best, make_pair(-r[i], i));
        }
      }
      //cout << best.S + 1 << '\n';
      cnt++;
      used[best.S] = true;
      ans[best.S + 1] = best.S + 1;
      for (int i = 0; i < n; i++) {
        if (!used[i] && inter(i, best.S)) {
          used[i] = true;
          ans[i + 1] = best.S + 1;
          cnt++;
        }
      }
    }
  }
  else {
    set<pair<int, int>> unused, lef, rig;
    for (int i = 0; i < n; i++) {
      unused.insert({-r[i], i});
      lef.insert({x[i] - r[i], i});
      rig.insert({x[i] + r[i], i});
    }
    while (!unused.empty()) {
      int id = unused.begin()->S;
      ans[id + 1] = id + 1;
      lef.erase({x[id] - r[id], id});
      rig.erase({x[id] + r[id], id});
      for (;;) {
        auto it = lef.upper_bound(make_pair(x[id] + r[id], 1e9));
        if (it == lef.begin()) {
          break;
        }
        it--;
        if (it->F < x[id] - r[id]) {
          break;
        }
        ans[it->S + 1] = id + 1;
        unused.erase({-r[it->S], it->S});
        lef.erase({x[it->S] - r[it->S], it->S});
        rig.erase({x[it->S] + r[it->S], it->S});
      }

      for (;;) {
        auto it = rig.lower_bound(make_pair(x[id] - r[id], 0));
        if (it == rig.end()) {
          break;
        }
        if (it->F > x[id] + r[id]) {
          break;
        }
        ans[it->S + 1] = id + 1;
        unused.erase({-r[it->S], it->S});
        lef.erase({x[it->S] - r[it->S], it->S});
        rig.erase({x[it->S] + r[it->S], it->S}); 
      } 
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 3 ms 768 KB Output is correct
22 Correct 161 ms 640 KB Output is correct
23 Correct 162 ms 760 KB Output is correct
24 Correct 163 ms 760 KB Output is correct
25 Correct 163 ms 640 KB Output is correct
26 Correct 175 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3061 ms 72828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 3048 ms 6264 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 15364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 3 ms 768 KB Output is correct
22 Correct 161 ms 640 KB Output is correct
23 Correct 162 ms 760 KB Output is correct
24 Correct 163 ms 760 KB Output is correct
25 Correct 163 ms 640 KB Output is correct
26 Correct 175 ms 640 KB Output is correct
27 Correct 5 ms 1024 KB Output is correct
28 Correct 5 ms 1024 KB Output is correct
29 Correct 5 ms 1024 KB Output is correct
30 Correct 700 ms 1004 KB Output is correct
31 Correct 723 ms 1020 KB Output is correct
32 Correct 722 ms 1016 KB Output is correct
33 Correct 48 ms 7288 KB Output is correct
34 Correct 58 ms 7160 KB Output is correct
35 Correct 60 ms 7032 KB Output is correct
36 Execution timed out 3040 ms 6136 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 3 ms 768 KB Output is correct
22 Correct 161 ms 640 KB Output is correct
23 Correct 162 ms 760 KB Output is correct
24 Correct 163 ms 760 KB Output is correct
25 Correct 163 ms 640 KB Output is correct
26 Correct 175 ms 640 KB Output is correct
27 Execution timed out 3061 ms 72828 KB Time limit exceeded
28 Halted 0 ms 0 KB -