답안 #757690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757690 2023-06-13T14:52:05 Z fanwen 원 고르기 (APIO18_circle_selection) C++17
100 / 100
1030 ms 48560 KB
/**
 *      author : pham van sam 
 *      created : 13 June 2023 (Tuesday)
 **/

#include <bits/stdc++.h>

using namespace std;
using namespace chrono;

#define int long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

const int MAXN = 3e5 + 5;

int N, ans[MAXN], ID[MAXN];

long long sqr(long long x) { return x * x; }

struct Circle_t {
    int x, y, r; // coordinate and radius
    Circle_t (int x = 0, int y = 0, int r = 0) : x(x), y(y), r(r) {}

    bool intersect(const Circle_t &a) const {
        return sqr(x - a.x) + sqr(y - a.y) <= sqr(r + a.r);
    }
} a[MAXN];

const int MAX = 1e9, INF = 2e9 + 7;
unordered_map <long long, vector <int>> mp;

void rescaling_grid(int sz) {
    mp.clear();
    FOR(i, 1, N) if(ans[i] == 0) {
        int x = a[i].x / sz, y = a[i].y / sz;
        long long tmp = 1LL * x * INF + y;
        mp[tmp].push_back(i);
    }
}

void eliminator(long long pos, int u) {
    if(!mp.count(pos)) return;
    vector <int> &points = mp[pos];
    for (int i = 0; i < (int) points.size(); ++i) {
        if(a[points[i]].intersect(a[u])) {
            ans[points[i]] = u;
            swap(points[i--], points.back());
            points.pop_back();
        }
    } 
    if(points.empty()) mp.erase(pos);
}


void process(void) {
    cin >> N;
    FOR(i, 1, N) {
        cin >> a[i].x >> a[i].y >> a[i].r;
        a[i].x += MAX;
        a[i].y += MAX;
    }
    iota(ID + 1, ID + N + 1, 1);
    sort(ID + 1, ID + N + 1, [&] (int i, int j) {
        return (a[i].r > a[j].r || (a[i].r == a[j].r && i < j));
    });
    int rMax = -1;
    FOR(i, 1, N) {
        int u = ID[i];
        if(ans[u]) continue;
        if(a[u].r < rMax / 2 || rMax == -1) {
            rMax = a[u].r;
            rescaling_grid(rMax);
        }
        FOR(cx, a[u].x / rMax - 2, a[u].x / rMax + 2) {
            FOR(cy, a[u].y / rMax - 2, a[u].y / rMax + 2) {
                eliminator(1LL * cx * INF + cy, u);
            }
        }
    }
    FOR(i, 1, N) cout << ans[i] << " \n"[i == N];
}

signed main() {

    #define TASK "TASK"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    auto start_time = steady_clock::now();
    int test = 1;
    // cin >> test;
    for (int i = 1; i <= test; ++i) {
        process();
        // cout << '\n';
    }

    auto end_time = steady_clock::now();

    cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7372 KB Output is correct
8 Correct 3 ms 7380 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 3 ms 7380 KB Output is correct
11 Correct 3 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 3 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 5 ms 7396 KB Output is correct
19 Correct 7 ms 7648 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 7 ms 7628 KB Output is correct
22 Correct 12 ms 8020 KB Output is correct
23 Correct 10 ms 8028 KB Output is correct
24 Correct 10 ms 8020 KB Output is correct
25 Correct 11 ms 8020 KB Output is correct
26 Correct 10 ms 8020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 14636 KB Output is correct
2 Correct 152 ms 14504 KB Output is correct
3 Correct 154 ms 14504 KB Output is correct
4 Correct 148 ms 15420 KB Output is correct
5 Correct 202 ms 22964 KB Output is correct
6 Correct 389 ms 32380 KB Output is correct
7 Correct 196 ms 24448 KB Output is correct
8 Correct 240 ms 26312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 224 ms 18656 KB Output is correct
3 Correct 835 ms 40220 KB Output is correct
4 Correct 882 ms 40236 KB Output is correct
5 Correct 810 ms 35740 KB Output is correct
6 Correct 278 ms 21180 KB Output is correct
7 Correct 106 ms 14808 KB Output is correct
8 Correct 21 ms 8916 KB Output is correct
9 Correct 1030 ms 39620 KB Output is correct
10 Correct 724 ms 34724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 744 ms 40260 KB Output is correct
2 Correct 685 ms 40240 KB Output is correct
3 Correct 269 ms 24068 KB Output is correct
4 Correct 658 ms 40184 KB Output is correct
5 Correct 660 ms 40292 KB Output is correct
6 Correct 175 ms 18984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7372 KB Output is correct
8 Correct 3 ms 7380 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 3 ms 7380 KB Output is correct
11 Correct 3 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 3 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 5 ms 7396 KB Output is correct
19 Correct 7 ms 7648 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 7 ms 7628 KB Output is correct
22 Correct 12 ms 8020 KB Output is correct
23 Correct 10 ms 8028 KB Output is correct
24 Correct 10 ms 8020 KB Output is correct
25 Correct 11 ms 8020 KB Output is correct
26 Correct 10 ms 8020 KB Output is correct
27 Correct 9 ms 8020 KB Output is correct
28 Correct 8 ms 7976 KB Output is correct
29 Correct 8 ms 7936 KB Output is correct
30 Correct 20 ms 8652 KB Output is correct
31 Correct 20 ms 8660 KB Output is correct
32 Correct 22 ms 8672 KB Output is correct
33 Correct 56 ms 12872 KB Output is correct
34 Correct 63 ms 13096 KB Output is correct
35 Correct 62 ms 12932 KB Output is correct
36 Correct 186 ms 21168 KB Output is correct
37 Correct 194 ms 21276 KB Output is correct
38 Correct 261 ms 21424 KB Output is correct
39 Correct 189 ms 19192 KB Output is correct
40 Correct 191 ms 19292 KB Output is correct
41 Correct 190 ms 19264 KB Output is correct
42 Correct 113 ms 20244 KB Output is correct
43 Correct 137 ms 21132 KB Output is correct
44 Correct 158 ms 21080 KB Output is correct
45 Correct 150 ms 21056 KB Output is correct
46 Correct 146 ms 21068 KB Output is correct
47 Correct 158 ms 21072 KB Output is correct
48 Correct 183 ms 21088 KB Output is correct
49 Correct 162 ms 21160 KB Output is correct
50 Correct 164 ms 21072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7372 KB Output is correct
8 Correct 3 ms 7380 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 3 ms 7380 KB Output is correct
11 Correct 3 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 3 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 5 ms 7396 KB Output is correct
19 Correct 7 ms 7648 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 7 ms 7628 KB Output is correct
22 Correct 12 ms 8020 KB Output is correct
23 Correct 10 ms 8028 KB Output is correct
24 Correct 10 ms 8020 KB Output is correct
25 Correct 11 ms 8020 KB Output is correct
26 Correct 10 ms 8020 KB Output is correct
27 Correct 150 ms 14636 KB Output is correct
28 Correct 152 ms 14504 KB Output is correct
29 Correct 154 ms 14504 KB Output is correct
30 Correct 148 ms 15420 KB Output is correct
31 Correct 202 ms 22964 KB Output is correct
32 Correct 389 ms 32380 KB Output is correct
33 Correct 196 ms 24448 KB Output is correct
34 Correct 240 ms 26312 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 224 ms 18656 KB Output is correct
37 Correct 835 ms 40220 KB Output is correct
38 Correct 882 ms 40236 KB Output is correct
39 Correct 810 ms 35740 KB Output is correct
40 Correct 278 ms 21180 KB Output is correct
41 Correct 106 ms 14808 KB Output is correct
42 Correct 21 ms 8916 KB Output is correct
43 Correct 1030 ms 39620 KB Output is correct
44 Correct 724 ms 34724 KB Output is correct
45 Correct 744 ms 40260 KB Output is correct
46 Correct 685 ms 40240 KB Output is correct
47 Correct 269 ms 24068 KB Output is correct
48 Correct 658 ms 40184 KB Output is correct
49 Correct 660 ms 40292 KB Output is correct
50 Correct 175 ms 18984 KB Output is correct
51 Correct 9 ms 8020 KB Output is correct
52 Correct 8 ms 7976 KB Output is correct
53 Correct 8 ms 7936 KB Output is correct
54 Correct 20 ms 8652 KB Output is correct
55 Correct 20 ms 8660 KB Output is correct
56 Correct 22 ms 8672 KB Output is correct
57 Correct 56 ms 12872 KB Output is correct
58 Correct 63 ms 13096 KB Output is correct
59 Correct 62 ms 12932 KB Output is correct
60 Correct 186 ms 21168 KB Output is correct
61 Correct 194 ms 21276 KB Output is correct
62 Correct 261 ms 21424 KB Output is correct
63 Correct 189 ms 19192 KB Output is correct
64 Correct 191 ms 19292 KB Output is correct
65 Correct 190 ms 19264 KB Output is correct
66 Correct 113 ms 20244 KB Output is correct
67 Correct 137 ms 21132 KB Output is correct
68 Correct 158 ms 21080 KB Output is correct
69 Correct 150 ms 21056 KB Output is correct
70 Correct 146 ms 21068 KB Output is correct
71 Correct 158 ms 21072 KB Output is correct
72 Correct 183 ms 21088 KB Output is correct
73 Correct 162 ms 21160 KB Output is correct
74 Correct 164 ms 21072 KB Output is correct
75 Correct 224 ms 24420 KB Output is correct
76 Correct 180 ms 23356 KB Output is correct
77 Correct 170 ms 23504 KB Output is correct
78 Correct 198 ms 23576 KB Output is correct
79 Correct 215 ms 24512 KB Output is correct
80 Correct 174 ms 23664 KB Output is correct
81 Correct 982 ms 48268 KB Output is correct
82 Correct 993 ms 48096 KB Output is correct
83 Correct 843 ms 48100 KB Output is correct
84 Correct 873 ms 48560 KB Output is correct
85 Correct 986 ms 48084 KB Output is correct
86 Correct 869 ms 48208 KB Output is correct
87 Correct 874 ms 48136 KB Output is correct
88 Correct 711 ms 40152 KB Output is correct
89 Correct 739 ms 40320 KB Output is correct
90 Correct 766 ms 40160 KB Output is correct
91 Correct 760 ms 40276 KB Output is correct
92 Correct 698 ms 40328 KB Output is correct
93 Correct 815 ms 47204 KB Output is correct
94 Correct 831 ms 47520 KB Output is correct
95 Correct 852 ms 47212 KB Output is correct
96 Correct 889 ms 47200 KB Output is correct
97 Correct 828 ms 47056 KB Output is correct
98 Correct 501 ms 39348 KB Output is correct
99 Correct 884 ms 47328 KB Output is correct
100 Correct 793 ms 47064 KB Output is correct
101 Correct 603 ms 42716 KB Output is correct
102 Correct 849 ms 46852 KB Output is correct
103 Correct 961 ms 46920 KB Output is correct
104 Correct 920 ms 47064 KB Output is correct
105 Correct 408 ms 44884 KB Output is correct
106 Correct 533 ms 46420 KB Output is correct
107 Correct 558 ms 46508 KB Output is correct
108 Correct 615 ms 46468 KB Output is correct
109 Correct 549 ms 46564 KB Output is correct
110 Correct 544 ms 46460 KB Output is correct
111 Correct 575 ms 46432 KB Output is correct
112 Correct 555 ms 46460 KB Output is correct
113 Correct 611 ms 46576 KB Output is correct
114 Correct 584 ms 46560 KB Output is correct
115 Correct 579 ms 46432 KB Output is correct
116 Correct 588 ms 46440 KB Output is correct