Submission #417993

# Submission time Handle Problem Language Result Execution time Memory
417993 2021-06-04T19:25:54 Z dolphingarlic Circle selection (APIO18_circle_selection) C++17
0 / 100
3000 ms 698908 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll MX = 1e9;

int ord[300001], ans[300001];
ll x[300001], y[300001], r[300001], min_grid[300001];
set<tuple<ll, ll, ll>> grids_in_circle[300001];
map<tuple<ll, ll, ll>, unordered_set<int>> circles_in_grid;
vector<pair<ll, int>> remaining;

bool circle_in_grid(int c, ll sx, ll sy, int scale) {
    ll x1 = sx << scale, x2 = (sx + 1) << scale;
    ll y1 = sy << scale, y2 = (sy + 1) << scale;
    // Case 1: The circle is inside the grid square
    if (x1 <= x[c] && x[c] <= x2 && y1 <= y[c] && y[c] <= y2) return true;
    // Case 2: The circle is outside the grid square
    if (min({
        hypot(x1 - x[c], y1 - y[c]),
        hypot(x1 - x[c], y2 - y[c]),
        hypot(x2 - x[c], y1 - y[c]),
        hypot(x2 - x[c], y2 - y[c])
    }) <= r[c]) return true;
    return false;
}

bool circles_intersect(int c1, int c2) {
    return hypot(x[c1] - x[c2], y[c1] - y[c2]) <= r[c1] + r[c2];
}

void remove_circle(int c) {
    for (auto g : grids_in_circle[c])
        circles_in_grid[g].erase(c);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i] >> r[i];
        x[i] += MX, y[i] += MX;
        min_grid[i] = 31 - __builtin_clz(2 * r[i]);
        for (int j = min_grid[i]; j <= 30; j++) {
            ll lbx = x[i] >> j, lby = y[i] >> j;
            for (ll dx : {-1, 0, 1}) for (ll dy : {-1, 0, 1})
                if (lbx + dx >= 0 && lby + dy >= 0 && circle_in_grid(i, lbx + dx, lby + dy, j)) {
                    grids_in_circle[i].insert({lbx + dx, lby + dy, j});
                    circles_in_grid[{lbx + dx, lby + dy, j}].insert(i);
                }
        }
    }
    iota(ord + 1, ord + n + 1, 1);
    sort(ord + 1, ord + n + 1, [](int A, int B) {
        if (r[A] == r[B]) return A < B;
        return r[A] > r[B];
    });
    for (int i = 1; i <= n; i++) {
        int curr = ord[i];
        if (ans[curr]) continue;
        for (auto g : grids_in_circle[curr]) for (int c : circles_in_grid[g]) {
            if (circles_intersect(curr, c)) {
                ans[c] = curr;
                remove_circle(c);
            }
        }
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Runtime error 22 ms 29076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2523 ms 698908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 29176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 445752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Runtime error 22 ms 29076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Runtime error 22 ms 29076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -