Submission #49140

# Submission time Handle Problem Language Result Execution time Memory
49140 2018-05-22T16:22:00 Z BThero Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 41480 KB
// Why am I so stupid? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

typedef long long ll;

using namespace std;

struct circle {
    int x, y, r, id;

    circle() {
        x = y = r = id = 0;
    }
} arr[300005];

map < ll, vector <int> > mm;

int ans[300005];

int u[300005];

int n, cur;

int block;

bool inter(circle a, circle b) {
    ll dist = (a.x - b.x) * 1ll * (a.x - b.x) + (a.y - b.y) * 1ll * (a.y - b.y);
    return dist <= (a.r + b.r) * 1ll * (a.r + b.r);
}

bool cmp(circle a, circle b) {
    if (a.r == b.r) {
        return a.id < b.id;
    }

    return a.r > b.r;
}

ll f(int x, int y) {
    return x * (ll)2e9 + y;
}

void divIntoBlocks(int st) {
    mm.clear();

    for (int i = st; i <= n; ++i) {
        if (ans[arr[i].id] == arr[i].id) {
            mm[f(arr[i].x / block, arr[i].y / block)].pb(i);
        }
    }
}

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r);
        arr[i].id = i;
    }

    sort(arr + 1, arr + n + 1, cmp);

    for (int i = 1; i <= n; ++i) {
        ans[i] = i;
    }

    vector <int> vv;

    for (int i = 1; i <= n; ++i) {
        if (ans[arr[i].id] != arr[i].id) {
            continue;
        }

        if (block == 0 || arr[i].r * 10ll <= block) {
            block = arr[i].r;
            divIntoBlocks(i + 1);
        }

        int cx = arr[i].x / block;
        int cy = arr[i].y / block;

        for (int x = cx - 2; x <= cx + 2; ++x) {
            for (int y = cy - 2; y <= cy + 2; ++y) {
                ll cur = f(x, y);
                auto P = mm.find(cur);
                vv.clear();

                if (P != mm.end()) {
                    for (int it : P -> se) {
                        if (inter(arr[i], arr[it])) {
                            ans[arr[it].id] = arr[i].id;
                        }
                        else {
                            vv.pb(it);
                        }
                    }

                    P -> se = vv;
                }
            }
        }

        /*

        for (int j = i + 1; j <= n; ++j) {
            if (ans[arr[j].id] == arr[j].id) {
                if (inter(arr[i], arr[j])) {
                    ans[arr[j].id] = arr[i].id;
                }
            }
        }

        */
    }

    for (int i = 1; i <= n; ++i) {
        printf("%d ", ans[i]);
    }
}

int main() {
#ifdef BThero
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // BThero

    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 5 ms 5096 KB Output is correct
3 Correct 7 ms 5148 KB Output is correct
4 Correct 6 ms 5148 KB Output is correct
5 Correct 7 ms 5148 KB Output is correct
6 Correct 7 ms 5196 KB Output is correct
7 Correct 6 ms 5196 KB Output is correct
8 Correct 6 ms 5272 KB Output is correct
9 Correct 6 ms 5272 KB Output is correct
10 Correct 6 ms 5272 KB Output is correct
11 Correct 6 ms 5272 KB Output is correct
12 Correct 6 ms 5316 KB Output is correct
13 Correct 6 ms 5316 KB Output is correct
14 Correct 6 ms 5316 KB Output is correct
15 Correct 8 ms 5316 KB Output is correct
16 Correct 6 ms 5316 KB Output is correct
17 Correct 6 ms 5316 KB Output is correct
18 Correct 6 ms 5316 KB Output is correct
19 Correct 9 ms 5372 KB Output is correct
20 Correct 9 ms 5372 KB Output is correct
21 Correct 13 ms 5388 KB Output is correct
22 Correct 20 ms 5920 KB Output is correct
23 Correct 21 ms 5920 KB Output is correct
24 Correct 20 ms 5920 KB Output is correct
25 Correct 18 ms 5932 KB Output is correct
26 Correct 20 ms 6056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 9836 KB Output is correct
2 Correct 224 ms 10912 KB Output is correct
3 Correct 220 ms 10912 KB Output is correct
4 Correct 229 ms 10912 KB Output is correct
5 Correct 293 ms 11052 KB Output is correct
6 Correct 1000 ms 24680 KB Output is correct
7 Correct 354 ms 24680 KB Output is correct
8 Correct 507 ms 24680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 24680 KB Output is correct
2 Correct 767 ms 24680 KB Output is correct
3 Correct 2654 ms 41344 KB Output is correct
4 Correct 2714 ms 41352 KB Output is correct
5 Correct 2261 ms 41352 KB Output is correct
6 Correct 836 ms 41352 KB Output is correct
7 Correct 336 ms 41352 KB Output is correct
8 Correct 65 ms 41352 KB Output is correct
9 Correct 2787 ms 41352 KB Output is correct
10 Correct 1876 ms 41352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2211 ms 41480 KB Output is correct
2 Correct 1601 ms 41480 KB Output is correct
3 Correct 623 ms 41480 KB Output is correct
4 Correct 1555 ms 41480 KB Output is correct
5 Correct 1407 ms 41480 KB Output is correct
6 Correct 300 ms 41480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 5 ms 5096 KB Output is correct
3 Correct 7 ms 5148 KB Output is correct
4 Correct 6 ms 5148 KB Output is correct
5 Correct 7 ms 5148 KB Output is correct
6 Correct 7 ms 5196 KB Output is correct
7 Correct 6 ms 5196 KB Output is correct
8 Correct 6 ms 5272 KB Output is correct
9 Correct 6 ms 5272 KB Output is correct
10 Correct 6 ms 5272 KB Output is correct
11 Correct 6 ms 5272 KB Output is correct
12 Correct 6 ms 5316 KB Output is correct
13 Correct 6 ms 5316 KB Output is correct
14 Correct 6 ms 5316 KB Output is correct
15 Correct 8 ms 5316 KB Output is correct
16 Correct 6 ms 5316 KB Output is correct
17 Correct 6 ms 5316 KB Output is correct
18 Correct 6 ms 5316 KB Output is correct
19 Correct 9 ms 5372 KB Output is correct
20 Correct 9 ms 5372 KB Output is correct
21 Correct 13 ms 5388 KB Output is correct
22 Correct 20 ms 5920 KB Output is correct
23 Correct 21 ms 5920 KB Output is correct
24 Correct 20 ms 5920 KB Output is correct
25 Correct 18 ms 5932 KB Output is correct
26 Correct 20 ms 6056 KB Output is correct
27 Correct 13 ms 41480 KB Output is correct
28 Correct 13 ms 41480 KB Output is correct
29 Correct 14 ms 41480 KB Output is correct
30 Correct 43 ms 41480 KB Output is correct
31 Correct 50 ms 41480 KB Output is correct
32 Correct 39 ms 41480 KB Output is correct
33 Correct 88 ms 41480 KB Output is correct
34 Correct 86 ms 41480 KB Output is correct
35 Correct 102 ms 41480 KB Output is correct
36 Correct 588 ms 41480 KB Output is correct
37 Correct 639 ms 41480 KB Output is correct
38 Correct 645 ms 41480 KB Output is correct
39 Correct 444 ms 41480 KB Output is correct
40 Correct 479 ms 41480 KB Output is correct
41 Correct 437 ms 41480 KB Output is correct
42 Correct 363 ms 41480 KB Output is correct
43 Correct 437 ms 41480 KB Output is correct
44 Correct 436 ms 41480 KB Output is correct
45 Correct 432 ms 41480 KB Output is correct
46 Correct 430 ms 41480 KB Output is correct
47 Correct 394 ms 41480 KB Output is correct
48 Correct 446 ms 41480 KB Output is correct
49 Correct 419 ms 41480 KB Output is correct
50 Correct 448 ms 41480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 5 ms 5096 KB Output is correct
3 Correct 7 ms 5148 KB Output is correct
4 Correct 6 ms 5148 KB Output is correct
5 Correct 7 ms 5148 KB Output is correct
6 Correct 7 ms 5196 KB Output is correct
7 Correct 6 ms 5196 KB Output is correct
8 Correct 6 ms 5272 KB Output is correct
9 Correct 6 ms 5272 KB Output is correct
10 Correct 6 ms 5272 KB Output is correct
11 Correct 6 ms 5272 KB Output is correct
12 Correct 6 ms 5316 KB Output is correct
13 Correct 6 ms 5316 KB Output is correct
14 Correct 6 ms 5316 KB Output is correct
15 Correct 8 ms 5316 KB Output is correct
16 Correct 6 ms 5316 KB Output is correct
17 Correct 6 ms 5316 KB Output is correct
18 Correct 6 ms 5316 KB Output is correct
19 Correct 9 ms 5372 KB Output is correct
20 Correct 9 ms 5372 KB Output is correct
21 Correct 13 ms 5388 KB Output is correct
22 Correct 20 ms 5920 KB Output is correct
23 Correct 21 ms 5920 KB Output is correct
24 Correct 20 ms 5920 KB Output is correct
25 Correct 18 ms 5932 KB Output is correct
26 Correct 20 ms 6056 KB Output is correct
27 Correct 242 ms 9836 KB Output is correct
28 Correct 224 ms 10912 KB Output is correct
29 Correct 220 ms 10912 KB Output is correct
30 Correct 229 ms 10912 KB Output is correct
31 Correct 293 ms 11052 KB Output is correct
32 Correct 1000 ms 24680 KB Output is correct
33 Correct 354 ms 24680 KB Output is correct
34 Correct 507 ms 24680 KB Output is correct
35 Correct 6 ms 24680 KB Output is correct
36 Correct 767 ms 24680 KB Output is correct
37 Correct 2654 ms 41344 KB Output is correct
38 Correct 2714 ms 41352 KB Output is correct
39 Correct 2261 ms 41352 KB Output is correct
40 Correct 836 ms 41352 KB Output is correct
41 Correct 336 ms 41352 KB Output is correct
42 Correct 65 ms 41352 KB Output is correct
43 Correct 2787 ms 41352 KB Output is correct
44 Correct 1876 ms 41352 KB Output is correct
45 Correct 2211 ms 41480 KB Output is correct
46 Correct 1601 ms 41480 KB Output is correct
47 Correct 623 ms 41480 KB Output is correct
48 Correct 1555 ms 41480 KB Output is correct
49 Correct 1407 ms 41480 KB Output is correct
50 Correct 300 ms 41480 KB Output is correct
51 Correct 13 ms 41480 KB Output is correct
52 Correct 13 ms 41480 KB Output is correct
53 Correct 14 ms 41480 KB Output is correct
54 Correct 43 ms 41480 KB Output is correct
55 Correct 50 ms 41480 KB Output is correct
56 Correct 39 ms 41480 KB Output is correct
57 Correct 88 ms 41480 KB Output is correct
58 Correct 86 ms 41480 KB Output is correct
59 Correct 102 ms 41480 KB Output is correct
60 Correct 588 ms 41480 KB Output is correct
61 Correct 639 ms 41480 KB Output is correct
62 Correct 645 ms 41480 KB Output is correct
63 Correct 444 ms 41480 KB Output is correct
64 Correct 479 ms 41480 KB Output is correct
65 Correct 437 ms 41480 KB Output is correct
66 Correct 363 ms 41480 KB Output is correct
67 Correct 437 ms 41480 KB Output is correct
68 Correct 436 ms 41480 KB Output is correct
69 Correct 432 ms 41480 KB Output is correct
70 Correct 430 ms 41480 KB Output is correct
71 Correct 394 ms 41480 KB Output is correct
72 Correct 446 ms 41480 KB Output is correct
73 Correct 419 ms 41480 KB Output is correct
74 Correct 448 ms 41480 KB Output is correct
75 Correct 269 ms 41480 KB Output is correct
76 Correct 253 ms 41480 KB Output is correct
77 Correct 245 ms 41480 KB Output is correct
78 Correct 272 ms 41480 KB Output is correct
79 Correct 272 ms 41480 KB Output is correct
80 Correct 240 ms 41480 KB Output is correct
81 Correct 2581 ms 41480 KB Output is correct
82 Correct 2295 ms 41480 KB Output is correct
83 Correct 2375 ms 41480 KB Output is correct
84 Correct 2475 ms 41480 KB Output is correct
85 Correct 2493 ms 41480 KB Output is correct
86 Correct 2472 ms 41480 KB Output is correct
87 Correct 2910 ms 41480 KB Output is correct
88 Correct 1471 ms 41480 KB Output is correct
89 Correct 1525 ms 41480 KB Output is correct
90 Correct 1682 ms 41480 KB Output is correct
91 Correct 1743 ms 41480 KB Output is correct
92 Correct 1498 ms 41480 KB Output is correct
93 Correct 1635 ms 41480 KB Output is correct
94 Correct 1379 ms 41480 KB Output is correct
95 Correct 1580 ms 41480 KB Output is correct
96 Correct 1638 ms 41480 KB Output is correct
97 Execution timed out 3038 ms 41480 KB Time limit exceeded
98 Halted 0 ms 0 KB -