Submission #265063

# Submission time Handle Problem Language Result Execution time Memory
265063 2020-08-14T12:45:28 Z extraterrestrial Circle selection (APIO18_circle_selection) C++14
19 / 100
3000 ms 74928 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;
      unused.erase(unused.begin());
      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 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 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 1 ms 384 KB Output is correct
10 Correct 0 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 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 204 ms 584 KB Output is correct
23 Correct 172 ms 632 KB Output is correct
24 Correct 185 ms 576 KB Output is correct
25 Correct 204 ms 512 KB Output is correct
26 Correct 221 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1749 ms 68180 KB Output is correct
2 Correct 1702 ms 74820 KB Output is correct
3 Correct 1778 ms 74632 KB Output is correct
4 Correct 1895 ms 74928 KB Output is correct
5 Correct 1543 ms 72568 KB Output is correct
6 Correct 1340 ms 72716 KB Output is correct
7 Correct 1437 ms 72768 KB Output is correct
8 Correct 1417 ms 72856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 3033 ms 3552 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3042 ms 7608 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 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 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 1 ms 384 KB Output is correct
10 Correct 0 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 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 204 ms 584 KB Output is correct
23 Correct 172 ms 632 KB Output is correct
24 Correct 185 ms 576 KB Output is correct
25 Correct 204 ms 512 KB Output is correct
26 Correct 221 ms 576 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 736 ms 760 KB Output is correct
31 Correct 782 ms 740 KB Output is correct
32 Correct 816 ms 740 KB Output is correct
33 Correct 53 ms 4088 KB Output is correct
34 Correct 53 ms 4088 KB Output is correct
35 Correct 90 ms 4088 KB Output is correct
36 Execution timed out 3053 ms 3536 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 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 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 1 ms 384 KB Output is correct
10 Correct 0 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 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 204 ms 584 KB Output is correct
23 Correct 172 ms 632 KB Output is correct
24 Correct 185 ms 576 KB Output is correct
25 Correct 204 ms 512 KB Output is correct
26 Correct 221 ms 576 KB Output is correct
27 Correct 1749 ms 68180 KB Output is correct
28 Correct 1702 ms 74820 KB Output is correct
29 Correct 1778 ms 74632 KB Output is correct
30 Correct 1895 ms 74928 KB Output is correct
31 Correct 1543 ms 72568 KB Output is correct
32 Correct 1340 ms 72716 KB Output is correct
33 Correct 1437 ms 72768 KB Output is correct
34 Correct 1417 ms 72856 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Execution timed out 3033 ms 3552 KB Time limit exceeded
37 Halted 0 ms 0 KB -