Submission #107111

#TimeUsernameProblemLanguageResultExecution timeMemory
107111tictaccatCircle selection (APIO18_circle_selection)C++14
49 / 100
3066 ms263924 KiB
#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 = 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 << " "; } cout << "\n"; return 0; }

Compilation message (stderr)

circle_selection.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...