Submission #107110

# Submission time Handle Problem Language Result Execution time Memory
107110 2019-04-22T03:31:52 Z tictaccat Circle selection (APIO18_circle_selection) C++14
37 / 100
3000 ms 299944 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();
    for (int i = 0; i < n; i++) {
        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 = 1e18;
    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 << " ";
    }

    return 0;
}

Compilation message

circle_selection.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 9 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 12 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Correct 10 ms 9728 KB Output is correct
8 Correct 10 ms 9728 KB Output is correct
9 Correct 12 ms 9728 KB Output is correct
10 Correct 11 ms 9728 KB Output is correct
11 Correct 12 ms 9856 KB Output is correct
12 Correct 13 ms 9856 KB Output is correct
13 Correct 11 ms 9856 KB Output is correct
14 Correct 10 ms 9856 KB Output is correct
15 Correct 12 ms 9728 KB Output is correct
16 Correct 12 ms 9856 KB Output is correct
17 Correct 12 ms 9856 KB Output is correct
18 Correct 12 ms 9856 KB Output is correct
19 Correct 20 ms 10232 KB Output is correct
20 Correct 22 ms 10240 KB Output is correct
21 Correct 26 ms 10232 KB Output is correct
22 Correct 56 ms 14088 KB Output is correct
23 Correct 58 ms 14088 KB Output is correct
24 Correct 64 ms 14088 KB Output is correct
25 Correct 65 ms 14088 KB Output is correct
26 Correct 54 ms 14060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1121 ms 41772 KB Output is correct
2 Correct 1219 ms 41220 KB Output is correct
3 Correct 1206 ms 41224 KB Output is correct
4 Correct 1159 ms 41772 KB Output is correct
5 Correct 1840 ms 40108 KB Output is correct
6 Execution timed out 3025 ms 75652 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Execution timed out 3027 ms 94080 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3115 ms 299944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 9 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 12 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Correct 10 ms 9728 KB Output is correct
8 Correct 10 ms 9728 KB Output is correct
9 Correct 12 ms 9728 KB Output is correct
10 Correct 11 ms 9728 KB Output is correct
11 Correct 12 ms 9856 KB Output is correct
12 Correct 13 ms 9856 KB Output is correct
13 Correct 11 ms 9856 KB Output is correct
14 Correct 10 ms 9856 KB Output is correct
15 Correct 12 ms 9728 KB Output is correct
16 Correct 12 ms 9856 KB Output is correct
17 Correct 12 ms 9856 KB Output is correct
18 Correct 12 ms 9856 KB Output is correct
19 Correct 20 ms 10232 KB Output is correct
20 Correct 22 ms 10240 KB Output is correct
21 Correct 26 ms 10232 KB Output is correct
22 Correct 56 ms 14088 KB Output is correct
23 Correct 58 ms 14088 KB Output is correct
24 Correct 64 ms 14088 KB Output is correct
25 Correct 65 ms 14088 KB Output is correct
26 Correct 54 ms 14060 KB Output is correct
27 Correct 42 ms 10928 KB Output is correct
28 Correct 28 ms 10880 KB Output is correct
29 Correct 35 ms 10876 KB Output is correct
30 Correct 135 ms 18536 KB Output is correct
31 Correct 164 ms 18536 KB Output is correct
32 Correct 133 ms 18700 KB Output is correct
33 Correct 392 ms 21104 KB Output is correct
34 Correct 355 ms 21384 KB Output is correct
35 Correct 718 ms 22104 KB Output is correct
36 Correct 2540 ms 95788 KB Output is correct
37 Correct 2608 ms 95416 KB Output is correct
38 Correct 2707 ms 95360 KB Output is correct
39 Correct 782 ms 33936 KB Output is correct
40 Correct 754 ms 33864 KB Output is correct
41 Correct 693 ms 33896 KB Output is correct
42 Correct 504 ms 26856 KB Output is correct
43 Correct 2015 ms 147592 KB Output is correct
44 Correct 1683 ms 147944 KB Output is correct
45 Correct 1805 ms 147836 KB Output is correct
46 Correct 1764 ms 147916 KB Output is correct
47 Correct 1719 ms 148052 KB Output is correct
48 Correct 1842 ms 147872 KB Output is correct
49 Correct 1789 ms 148072 KB Output is correct
50 Correct 1727 ms 147848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 9 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 12 ms 9728 KB Output is correct
5 Correct 11 ms 9728 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Correct 10 ms 9728 KB Output is correct
8 Correct 10 ms 9728 KB Output is correct
9 Correct 12 ms 9728 KB Output is correct
10 Correct 11 ms 9728 KB Output is correct
11 Correct 12 ms 9856 KB Output is correct
12 Correct 13 ms 9856 KB Output is correct
13 Correct 11 ms 9856 KB Output is correct
14 Correct 10 ms 9856 KB Output is correct
15 Correct 12 ms 9728 KB Output is correct
16 Correct 12 ms 9856 KB Output is correct
17 Correct 12 ms 9856 KB Output is correct
18 Correct 12 ms 9856 KB Output is correct
19 Correct 20 ms 10232 KB Output is correct
20 Correct 22 ms 10240 KB Output is correct
21 Correct 26 ms 10232 KB Output is correct
22 Correct 56 ms 14088 KB Output is correct
23 Correct 58 ms 14088 KB Output is correct
24 Correct 64 ms 14088 KB Output is correct
25 Correct 65 ms 14088 KB Output is correct
26 Correct 54 ms 14060 KB Output is correct
27 Correct 1121 ms 41772 KB Output is correct
28 Correct 1219 ms 41220 KB Output is correct
29 Correct 1206 ms 41224 KB Output is correct
30 Correct 1159 ms 41772 KB Output is correct
31 Correct 1840 ms 40108 KB Output is correct
32 Execution timed out 3025 ms 75652 KB Time limit exceeded
33 Halted 0 ms 0 KB -