답안 #107112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107112 2019-04-22T03:43:26 Z tictaccat 원 고르기 (APIO18_circle_selection) C++14
19 / 100
3000 ms 270652 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAX = 3e5;

int n;
int gridSize;

vector<pair<int,pair<int,int>>> circles(MAX);
unordered_map<int,vector<int>> grid;
set<pair<int,int>> cur;
vector<int> elim(MAX,-1);

int dist(pair<int,int> p1, pair<int,int> p2) {return (p2.first-p1.first)*(p2.first-p1.first) + (p2.second-p1.second)*(p2.second-p1.second);}
bool intsct(pair<int,pair<int,int>> c1, pair<int,pair<int,int>> c2) {return dist(c1.second,c2.second) <= (c1.first+c2.first)*(c1.first+c2.first);}
int toInt(int xbin, int ybin) {return xbin + ybin * (int)(5e9);}

void makeGrid() {
    grid.clear();
    grid.reserve(count(elim.begin(),elim.end(),-1));
    for (int i = 0; i < n; i++) {
        if (elim[i] != -1) continue;
        auto c = circles[i]; auto p = c.second;
        int xbin = p.first/gridSize; int ybin = p.second/gridSize;
       // cout << toInt(p) << "\n";
        //assert (toInt(p) < numeric_limits<long long>::max());
        if (grid.count(toInt(xbin,ybin)) == 0) grid[toInt(xbin,ybin)] = {i};
        else grid[toInt(xbin,ybin)].push_back(i);
    }
}

main() {

    // cin.tie(0);
    // ios::sync_with_stdio(false);

    cin >> n;

    for (int i = 0; i < n; i++) {
        int x,y,r; cin >> x >> y >> r;
        circles[i] = make_pair(r,make_pair(x,y));
        cur.insert(make_pair(-r,i));
    }
    
    gridSize = -(cur.begin()->first);
    makeGrid();

    while (cur.size() > 0) {
        int i = cur.begin()->second;
        auto top = circles[i]; auto p = top.second; 
        // if (top.first < gridSize/2) {
        //     gridSize = top.first;
        //     makeGrid();
        // }
        int xbinTop = p.first/gridSize; int ybinTop = p.second/gridSize;
        for (int xbin = xbinTop-2; xbin <= xbinTop + 2; xbin++) {
            for (int ybin = ybinTop-2; ybin <= ybinTop + 2; ybin++) {
                for (int j: grid[toInt(xbin,ybin)]) {
                    if (elim[j] == -1 && intsct(top,circles[j])) {
                    //    cout << i+1 << " " << j+1 << "\n";
                        elim[j] = i;
                        assert(cur.count(make_pair(-circles[j].first,j))  == 1);
                        cur.erase(make_pair(-circles[j].first,j)); 
                    }
                }
            }
        }
      ///  break;
    }
    
    for (int i = 0; i < n; i++) {
        cout << elim[i]+1 << " ";
    }

    cout << "\n";

    return 0;
}

Compilation message

circle_selection.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 12 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 14 ms 12288 KB Output is correct
7 Correct 13 ms 12288 KB Output is correct
8 Correct 13 ms 12288 KB Output is correct
9 Correct 12 ms 12288 KB Output is correct
10 Correct 14 ms 12416 KB Output is correct
11 Correct 13 ms 12416 KB Output is correct
12 Correct 15 ms 12416 KB Output is correct
13 Correct 12 ms 12416 KB Output is correct
14 Correct 12 ms 12416 KB Output is correct
15 Correct 14 ms 12544 KB Output is correct
16 Correct 14 ms 12288 KB Output is correct
17 Correct 15 ms 12288 KB Output is correct
18 Correct 17 ms 12416 KB Output is correct
19 Correct 22 ms 12800 KB Output is correct
20 Correct 23 ms 12832 KB Output is correct
21 Correct 27 ms 12800 KB Output is correct
22 Correct 47 ms 18552 KB Output is correct
23 Correct 54 ms 18424 KB Output is correct
24 Correct 43 ms 18552 KB Output is correct
25 Correct 46 ms 18424 KB Output is correct
26 Correct 47 ms 18552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1085 ms 36264 KB Output is correct
2 Correct 1295 ms 37096 KB Output is correct
3 Correct 1050 ms 36012 KB Output is correct
4 Correct 1016 ms 36064 KB Output is correct
5 Correct 1045 ms 37880 KB Output is correct
6 Correct 2105 ms 76716 KB Output is correct
7 Correct 1201 ms 39004 KB Output is correct
8 Correct 1315 ms 40184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 12288 KB Output is correct
2 Correct 1793 ms 150192 KB Output is correct
3 Execution timed out 3035 ms 234440 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3056 ms 270652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 12 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 14 ms 12288 KB Output is correct
7 Correct 13 ms 12288 KB Output is correct
8 Correct 13 ms 12288 KB Output is correct
9 Correct 12 ms 12288 KB Output is correct
10 Correct 14 ms 12416 KB Output is correct
11 Correct 13 ms 12416 KB Output is correct
12 Correct 15 ms 12416 KB Output is correct
13 Correct 12 ms 12416 KB Output is correct
14 Correct 12 ms 12416 KB Output is correct
15 Correct 14 ms 12544 KB Output is correct
16 Correct 14 ms 12288 KB Output is correct
17 Correct 15 ms 12288 KB Output is correct
18 Correct 17 ms 12416 KB Output is correct
19 Correct 22 ms 12800 KB Output is correct
20 Correct 23 ms 12832 KB Output is correct
21 Correct 27 ms 12800 KB Output is correct
22 Correct 47 ms 18552 KB Output is correct
23 Correct 54 ms 18424 KB Output is correct
24 Correct 43 ms 18552 KB Output is correct
25 Correct 46 ms 18424 KB Output is correct
26 Correct 47 ms 18552 KB Output is correct
27 Correct 33 ms 13048 KB Output is correct
28 Correct 34 ms 13048 KB Output is correct
29 Correct 34 ms 13080 KB Output is correct
30 Correct 91 ms 24572 KB Output is correct
31 Correct 89 ms 24568 KB Output is correct
32 Correct 89 ms 24568 KB Output is correct
33 Correct 350 ms 20208 KB Output is correct
34 Correct 371 ms 20172 KB Output is correct
35 Correct 388 ms 20148 KB Output is correct
36 Correct 1861 ms 153704 KB Output is correct
37 Correct 1777 ms 153728 KB Output is correct
38 Correct 1837 ms 153572 KB Output is correct
39 Execution timed out 3034 ms 19696 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 12 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 14 ms 12288 KB Output is correct
7 Correct 13 ms 12288 KB Output is correct
8 Correct 13 ms 12288 KB Output is correct
9 Correct 12 ms 12288 KB Output is correct
10 Correct 14 ms 12416 KB Output is correct
11 Correct 13 ms 12416 KB Output is correct
12 Correct 15 ms 12416 KB Output is correct
13 Correct 12 ms 12416 KB Output is correct
14 Correct 12 ms 12416 KB Output is correct
15 Correct 14 ms 12544 KB Output is correct
16 Correct 14 ms 12288 KB Output is correct
17 Correct 15 ms 12288 KB Output is correct
18 Correct 17 ms 12416 KB Output is correct
19 Correct 22 ms 12800 KB Output is correct
20 Correct 23 ms 12832 KB Output is correct
21 Correct 27 ms 12800 KB Output is correct
22 Correct 47 ms 18552 KB Output is correct
23 Correct 54 ms 18424 KB Output is correct
24 Correct 43 ms 18552 KB Output is correct
25 Correct 46 ms 18424 KB Output is correct
26 Correct 47 ms 18552 KB Output is correct
27 Correct 1085 ms 36264 KB Output is correct
28 Correct 1295 ms 37096 KB Output is correct
29 Correct 1050 ms 36012 KB Output is correct
30 Correct 1016 ms 36064 KB Output is correct
31 Correct 1045 ms 37880 KB Output is correct
32 Correct 2105 ms 76716 KB Output is correct
33 Correct 1201 ms 39004 KB Output is correct
34 Correct 1315 ms 40184 KB Output is correct
35 Correct 14 ms 12288 KB Output is correct
36 Correct 1793 ms 150192 KB Output is correct
37 Execution timed out 3035 ms 234440 KB Time limit exceeded
38 Halted 0 ms 0 KB -