Submission #107113

# Submission time Handle Problem Language Result Execution time Memory
107113 2019-04-22T03:45:23 Z tictaccat Circle selection (APIO18_circle_selection) C++14
49 / 100
3000 ms 267092 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();

    int k = n+3;

    while (cur.size() > 0 && k--) {
        int i = cur.begin()->second;
        auto top = circles[i]; auto p = top.second; 
        if (top.first < gridSize/4) {
            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() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12288 KB Output is correct
2 Correct 14 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 11 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 12 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 13 ms 12260 KB Output is correct
10 Correct 13 ms 12288 KB Output is correct
11 Correct 18 ms 14712 KB Output is correct
12 Correct 17 ms 14720 KB Output is correct
13 Correct 17 ms 14720 KB Output is correct
14 Correct 17 ms 14692 KB Output is correct
15 Correct 18 ms 14720 KB Output is correct
16 Correct 18 ms 14720 KB Output is correct
17 Correct 15 ms 12416 KB Output is correct
18 Correct 18 ms 12288 KB Output is correct
19 Correct 26 ms 12672 KB Output is correct
20 Correct 25 ms 12664 KB Output is correct
21 Correct 29 ms 14968 KB Output is correct
22 Correct 54 ms 17024 KB Output is correct
23 Correct 47 ms 17016 KB Output is correct
24 Correct 54 ms 17016 KB Output is correct
25 Correct 59 ms 17144 KB Output is correct
26 Correct 52 ms 17144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1156 ms 35324 KB Output is correct
2 Correct 1219 ms 34684 KB Output is correct
3 Correct 1239 ms 35596 KB Output is correct
4 Correct 1122 ms 35304 KB Output is correct
5 Correct 1207 ms 35456 KB Output is correct
6 Correct 2914 ms 74344 KB Output is correct
7 Correct 1242 ms 36780 KB Output is correct
8 Correct 1436 ms 38080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12288 KB Output is correct
2 Correct 2081 ms 123984 KB Output is correct
3 Execution timed out 3045 ms 225288 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3039 ms 267092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12288 KB Output is correct
2 Correct 14 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 11 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 12 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 13 ms 12260 KB Output is correct
10 Correct 13 ms 12288 KB Output is correct
11 Correct 18 ms 14712 KB Output is correct
12 Correct 17 ms 14720 KB Output is correct
13 Correct 17 ms 14720 KB Output is correct
14 Correct 17 ms 14692 KB Output is correct
15 Correct 18 ms 14720 KB Output is correct
16 Correct 18 ms 14720 KB Output is correct
17 Correct 15 ms 12416 KB Output is correct
18 Correct 18 ms 12288 KB Output is correct
19 Correct 26 ms 12672 KB Output is correct
20 Correct 25 ms 12664 KB Output is correct
21 Correct 29 ms 14968 KB Output is correct
22 Correct 54 ms 17024 KB Output is correct
23 Correct 47 ms 17016 KB Output is correct
24 Correct 54 ms 17016 KB Output is correct
25 Correct 59 ms 17144 KB Output is correct
26 Correct 52 ms 17144 KB Output is correct
27 Correct 47 ms 15540 KB Output is correct
28 Correct 37 ms 13148 KB Output is correct
29 Correct 39 ms 13112 KB Output is correct
30 Correct 94 ms 22008 KB Output is correct
31 Correct 113 ms 21752 KB Output is correct
32 Correct 121 ms 21732 KB Output is correct
33 Correct 343 ms 20204 KB Output is correct
34 Correct 351 ms 20180 KB Output is correct
35 Correct 331 ms 20428 KB Output is correct
36 Correct 2017 ms 126208 KB Output is correct
37 Correct 2166 ms 126080 KB Output is correct
38 Correct 2154 ms 125952 KB Output is correct
39 Correct 603 ms 35776 KB Output is correct
40 Correct 641 ms 35856 KB Output is correct
41 Correct 607 ms 35892 KB Output is correct
42 Correct 481 ms 26932 KB Output is correct
43 Correct 1609 ms 137104 KB Output is correct
44 Correct 1628 ms 137472 KB Output is correct
45 Correct 1535 ms 137088 KB Output is correct
46 Correct 1699 ms 137536 KB Output is correct
47 Correct 1585 ms 137472 KB Output is correct
48 Correct 1517 ms 137472 KB Output is correct
49 Correct 1731 ms 137600 KB Output is correct
50 Correct 1834 ms 137344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12288 KB Output is correct
2 Correct 14 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 11 ms 12288 KB Output is correct
5 Correct 12 ms 12288 KB Output is correct
6 Correct 12 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 13 ms 12260 KB Output is correct
10 Correct 13 ms 12288 KB Output is correct
11 Correct 18 ms 14712 KB Output is correct
12 Correct 17 ms 14720 KB Output is correct
13 Correct 17 ms 14720 KB Output is correct
14 Correct 17 ms 14692 KB Output is correct
15 Correct 18 ms 14720 KB Output is correct
16 Correct 18 ms 14720 KB Output is correct
17 Correct 15 ms 12416 KB Output is correct
18 Correct 18 ms 12288 KB Output is correct
19 Correct 26 ms 12672 KB Output is correct
20 Correct 25 ms 12664 KB Output is correct
21 Correct 29 ms 14968 KB Output is correct
22 Correct 54 ms 17024 KB Output is correct
23 Correct 47 ms 17016 KB Output is correct
24 Correct 54 ms 17016 KB Output is correct
25 Correct 59 ms 17144 KB Output is correct
26 Correct 52 ms 17144 KB Output is correct
27 Correct 1156 ms 35324 KB Output is correct
28 Correct 1219 ms 34684 KB Output is correct
29 Correct 1239 ms 35596 KB Output is correct
30 Correct 1122 ms 35304 KB Output is correct
31 Correct 1207 ms 35456 KB Output is correct
32 Correct 2914 ms 74344 KB Output is correct
33 Correct 1242 ms 36780 KB Output is correct
34 Correct 1436 ms 38080 KB Output is correct
35 Correct 13 ms 12288 KB Output is correct
36 Correct 2081 ms 123984 KB Output is correct
37 Execution timed out 3045 ms 225288 KB Time limit exceeded
38 Halted 0 ms 0 KB -