답안 #698696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698696 2023-02-14T08:08:36 Z vjudge1 원 고르기 (APIO18_circle_selection) C++17
7 / 100
3000 ms 70924 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int M = 3e5+5, MOD = 1e9;
struct circle {int x, y, r, i;};
bool operator<(circle a, circle b) {if (a.r == b.r) return a.i < b.i; return a.r > b.r;};
int p[M], l[M], r[M];
    
int sq(int a) {return a*a;}
int dist(circle a, circle b) {
    return sq(a.x-b.x) + sq(a.y-b.y);
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int n;
    cin >> n;

    int mx = INT_MIN;
    set<circle> v;
    set<pair<int, int>> rng;
    for (int i = 1; i <= n; i++) {
        int x, y, r_;
        cin >> x >> y >> r_;

        l[i] = x-r_;
        r[i] = x+r_;
        mx = max(mx, y);
        rng.insert({l[i], i});
        rng.insert({r[i], i});
        v.insert({x, y, r_, i});
    }

    if (mx) {
        while (v.size()) {
            auto a = *v.begin();
            v.erase(v.begin());
            // cout << a.i << ": ";
            p[a.i] = a.i;

            set<circle> st;
            for (auto b:v) {
                if (dist(a, b) <= sq(a.r+b.r)) {
                    p[b.i] = a.i;
                    // cout << b.i << ' ';
                    st.insert(b);
                }
            } //cout << endl;

            for (auto c:st) v.erase(c);
        }
    } else {
        vector<int> ind;
        for (int i = 1; i <= n; i++) ind.push_back(i);
        sort(ind.begin(), ind.end(), [](int a, int b) {if (r[a]-l[a] == r[b]-l[b]) return a < b; return r[a]-l[a] > r[b]-l[b];});
        for (int a:ind) {
            if (rng.find({l[a], a}) == rng.end()) continue;
            p[a] = a;
            auto end = rng.find({r[a], a});
            while (true) {
                auto nxt = rng.upper_bound({l[a], a});
                if (nxt == end) break;
                // cout << l[nxt->second] << ',' << r[nxt->second] << ' ' << nxt->second << endl;
                // for (auto [a, b]:rng) cout <<"{"<< a << ", " << b << "}, "; cout << endl;
                p[nxt->second] = a;

                rng.erase({l[nxt->second], nxt->second});
                rng.erase({r[nxt->second], nxt->second});
                
            }

            auto begin = rng.lower_bound({l[a], a});
            rng.erase(end);
        }
    }

    for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;

    return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
-------
7 
0 0 2
-1 0 1
0 0 1
1 0 1
10 0 5 
11 0 5
50 0 1
-------
*/

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:76:18: warning: variable 'begin' set but not used [-Wunused-but-set-variable]
   76 |             auto begin = rng.lower_bound({l[a], a});
      |                  ^~~~~
circle_selection.cpp:81:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   81 |     for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
      |     ^~~
circle_selection.cpp:81:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   81 |     for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
      |                                                       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
20 Correct 7 ms 1876 KB Output is correct
21 Correct 7 ms 1748 KB Output is correct
22 Correct 194 ms 1468 KB Output is correct
23 Correct 183 ms 1464 KB Output is correct
24 Correct 209 ms 1484 KB Output is correct
25 Correct 183 ms 1472 KB Output is correct
26 Correct 186 ms 1588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1204 ms 70924 KB Output is correct
2 Correct 1251 ms 70880 KB Output is correct
3 Correct 1234 ms 70884 KB Output is correct
4 Correct 1248 ms 70888 KB Output is correct
5 Incorrect 1012 ms 70860 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 3062 ms 22908 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3071 ms 66156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
20 Correct 7 ms 1876 KB Output is correct
21 Correct 7 ms 1748 KB Output is correct
22 Correct 194 ms 1468 KB Output is correct
23 Correct 183 ms 1464 KB Output is correct
24 Correct 209 ms 1484 KB Output is correct
25 Correct 183 ms 1472 KB Output is correct
26 Correct 186 ms 1588 KB Output is correct
27 Correct 14 ms 3412 KB Output is correct
28 Correct 14 ms 3392 KB Output is correct
29 Correct 15 ms 3328 KB Output is correct
30 Correct 965 ms 2584 KB Output is correct
31 Correct 947 ms 2584 KB Output is correct
32 Correct 932 ms 2636 KB Output is correct
33 Correct 262 ms 31436 KB Output is correct
34 Correct 258 ms 31368 KB Output is correct
35 Correct 295 ms 30488 KB Output is correct
36 Execution timed out 3066 ms 23012 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
20 Correct 7 ms 1876 KB Output is correct
21 Correct 7 ms 1748 KB Output is correct
22 Correct 194 ms 1468 KB Output is correct
23 Correct 183 ms 1464 KB Output is correct
24 Correct 209 ms 1484 KB Output is correct
25 Correct 183 ms 1472 KB Output is correct
26 Correct 186 ms 1588 KB Output is correct
27 Correct 1204 ms 70924 KB Output is correct
28 Correct 1251 ms 70880 KB Output is correct
29 Correct 1234 ms 70884 KB Output is correct
30 Correct 1248 ms 70888 KB Output is correct
31 Incorrect 1012 ms 70860 KB Output isn't correct
32 Halted 0 ms 0 KB -