Submission #970277

# Submission time Handle Problem Language Result Execution time Memory
970277 2024-04-26T10:07:48 Z steveonalex Circle selection (APIO18_circle_selection) C++17
75 / 100
2250 ms 62756 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 3e5 + 69;
const ll INF = 2e9;
int n; 
int ans[N];
vector<array<ll, 4>> a;

ll sqr(ll x){return x * x;}
ll block_sz;
map<pair<ll, ll>, vector<int>> grid;

pair<ll, ll> dumb_down(pair<ll, ll> a){
    return {a.first / block_sz, a.second / block_sz};
}

void set_up(ll arg){
    block_sz = arg;

    grid.clear();
    for(int i= 1; i<=n; ++i) if (ans[i] == 0){
        grid[dumb_down(make_pair(a[i][0], a[i][1]))].push_back(i);
    }
}

ll dis(pair<ll, ll> a, pair<ll, ll> b){return sqr(a.first - b.first) + sqr(a.second - b.second);}

bool check(pair<ll, ll> point, ll r, pair<ll, ll> des){
    if (des.first < 0 || des.second < 0) return false;
    for(int x = 0; x <= 1; ++x) for(int y = 0; y<=1; ++y){
        pair<ll, ll> ligma = {des.first * block_sz, des.second * block_sz};
        if (x) ligma.first += block_sz - 1;
        if (y) ligma.second += block_sz - 1;
        if (dis(point, ligma) <= sqr(r)) return true;
    }
    return false;
}

bool query(int i, int j){
    return sqr(a[i][0] - a[j][0]) + sqr(a[i][1] - a[j][1]) <= sqr(a[i][2] + a[j][2]);
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i<=n; ++i) {
        for(int j = 0; j < 3; ++j) cin >> a[i][j];
        a[i][0] += INF; a[i][1] += INF;
        a[i][3] = i;
    }

    vector<array<ll, 4>> b = a;
    sort(1 + ALL(b), [](array<ll, 4> x, array<ll, 4> y){
        if (x[2] != y[2]) return x[2] > y[2];
        return x[3] < y[3];
    });

    set_up((b[1][2] + 1) / 2);
    for(int i = 1; i<=n; ++i) if (ans[b[i][3]] == 0){
        int _i = b[i][3];
        ans[_i] = _i;

        if (b[i][2] < block_sz)
            set_up((b[i][2] + 1) / 2);

        pair<ll, ll> cur = make_pair(b[i][0], b[i][1]);
        pair<ll, ll> magnifico = dumb_down(cur);
        for(int x = -6; x <= 6; ++x) for(int y = -6; y<=6; ++y) {
            pair<ll, ll> cu = make_pair(magnifico.first + x, magnifico.second + y);
            if (!check(cur, b[i][2] * 2, cu) || !grid.count(cu)) continue;
            for(int j: grid[cu]){
                if (ans[j] == 0 && query(_i, j)) ans[j] = _i;
            }
        }
    }

    for(int i = 1; i<=n; ++i) 
        cout << ans[i] << " "; 
    cout << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 19 ms 1368 KB Output is correct
23 Correct 22 ms 1352 KB Output is correct
24 Correct 18 ms 1368 KB Output is correct
25 Correct 17 ms 1372 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 22620 KB Output is correct
2 Correct 120 ms 22980 KB Output is correct
3 Correct 123 ms 23572 KB Output is correct
4 Correct 110 ms 22704 KB Output is correct
5 Incorrect 178 ms 25644 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 538 ms 18628 KB Output is correct
3 Correct 2053 ms 55244 KB Output is correct
4 Correct 2035 ms 55332 KB Output is correct
5 Correct 1804 ms 51540 KB Output is correct
6 Correct 610 ms 26704 KB Output is correct
7 Correct 290 ms 14420 KB Output is correct
8 Correct 39 ms 3336 KB Output is correct
9 Correct 2133 ms 55032 KB Output is correct
10 Correct 1710 ms 51372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2250 ms 55280 KB Output is correct
2 Correct 1134 ms 55180 KB Output is correct
3 Correct 625 ms 44264 KB Output is correct
4 Correct 1628 ms 62652 KB Output is correct
5 Correct 1578 ms 62756 KB Output is correct
6 Correct 255 ms 38288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 19 ms 1368 KB Output is correct
23 Correct 22 ms 1352 KB Output is correct
24 Correct 18 ms 1368 KB Output is correct
25 Correct 17 ms 1372 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
27 Correct 5 ms 1044 KB Output is correct
28 Correct 4 ms 1116 KB Output is correct
29 Correct 4 ms 1048 KB Output is correct
30 Correct 42 ms 2236 KB Output is correct
31 Correct 40 ms 2140 KB Output is correct
32 Correct 38 ms 2240 KB Output is correct
33 Correct 43 ms 8012 KB Output is correct
34 Correct 41 ms 8148 KB Output is correct
35 Correct 45 ms 7864 KB Output is correct
36 Correct 460 ms 18516 KB Output is correct
37 Correct 479 ms 18584 KB Output is correct
38 Correct 473 ms 18580 KB Output is correct
39 Correct 222 ms 17036 KB Output is correct
40 Correct 243 ms 16848 KB Output is correct
41 Correct 224 ms 17000 KB Output is correct
42 Correct 242 ms 18376 KB Output is correct
43 Correct 403 ms 18712 KB Output is correct
44 Correct 412 ms 18520 KB Output is correct
45 Correct 419 ms 18456 KB Output is correct
46 Correct 410 ms 18516 KB Output is correct
47 Correct 398 ms 18512 KB Output is correct
48 Correct 413 ms 18464 KB Output is correct
49 Correct 402 ms 18476 KB Output is correct
50 Correct 417 ms 18708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 19 ms 1368 KB Output is correct
23 Correct 22 ms 1352 KB Output is correct
24 Correct 18 ms 1368 KB Output is correct
25 Correct 17 ms 1372 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
27 Correct 114 ms 22620 KB Output is correct
28 Correct 120 ms 22980 KB Output is correct
29 Correct 123 ms 23572 KB Output is correct
30 Correct 110 ms 22704 KB Output is correct
31 Incorrect 178 ms 25644 KB Output isn't correct
32 Halted 0 ms 0 KB -