Submission #741232

#TimeUsernameProblemLanguageResultExecution timeMemory
741232speedyArdaCircle selection (APIO18_circle_selection)C++14
7 / 100
435 ms25548 KiB
#include "bits/stdc++.h" #pragma GCC optimize("O1, O2, O3, Ofast, unroll-loops") using namespace std; const int MAXN = 3e5+5; vector< pair < pair<int, int>, pair<int, int> > > circles; vector<int> ans(MAXN, 0); int id[MAXN]; bool cmp(int &a, int &b) { if(circles[a].second.first != circles[b].second.first) return circles[a].second.first > circles[b].second.first; return circles[a].second.second < circles[b].second.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int maxy = -1e9; for(int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; maxy = max(maxy, y); circles.push_back({{x, y}, {r, i}}); id[i] = i; } sort(id, id + n, cmp); //cout << "s\n"; if(n <= 5e3 && maxy != 0) { for(int idx = 0; idx < n; idx++) { int i = id[idx]; if(ans[circles[i].second.second] != 0) continue; //cout << circles[i].second.second << "\n"; ans[circles[i].second.second] = circles[i].second.second + 1; for(int a = 0; a < n; a++) { if(ans[circles[a].second.second] == 0) { long double dist = sqrt(pow(abs(circles[i].first.first - circles[a].first.first), 2) + pow(abs(circles[i].first.second - circles[a].first.second), 2)); if(dist <= circles[i].second.first + circles[a].second.first) ans[circles[a].second.second] = circles[i].second.second + 1; } } } } else { multiset< pair<int, int> > elems; for(int i = 0; i < n; i++) { elems.insert({circles[i].first.first, circles[i].second.second}); } for(int idx = 0; idx < n; idx++) { int i = id[idx]; if(ans[circles[i].second.second] != 0) continue; //cout << circles[i].second.second << "\n"; auto it = elems.find({circles[i].first.first, circles[i].second.second}); auto prev = it; vector<int> toerase; if(it != elems.begin()) { it--; while(true) { pair<int, int> temp = (*it); if(abs(circles[i].first.first - temp.first) <= circles[i].second.first + circles[temp.second].second.first) { toerase.push_back(temp.second); } else break; if(it == elems.begin()) break; it--; } } it = prev; while(it != elems.end()) { pair<int, int> temp = (*it); if(abs(circles[i].first.first - temp.first) <= circles[i].second.first + circles[temp.second].second.first) { toerase.push_back(temp.second); } else break; it++; } for(int e : toerase) { ans[circles[e].second.second] = circles[i].second.second + 1; elems.erase(elems.find({circles[e].first.first, circles[e].second.second})); } } } for(int i = 0; i < n; i++) cout << ans[i] << " "; cout << "\n"; }

Compilation message (stderr)

circle_selection.cpp:2:55: warning: bad option '-f O2' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize("O1, O2, O3, Ofast, unroll-loops")
      |                                                       ^
circle_selection.cpp:2:55: warning: bad option '-f O3' to pragma 'optimize' [-Wpragmas]
circle_selection.cpp:2:55: warning: bad option '-f Ofast' to pragma 'optimize' [-Wpragmas]
circle_selection.cpp:2:55: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
circle_selection.cpp:8:24: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
    8 | bool cmp(int &a, int &b)
      |                        ^
circle_selection.cpp:8:24: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
circle_selection.cpp:8:24: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
circle_selection.cpp:8:24: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
circle_selection.cpp:14:10: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
   14 | int main()
      |          ^
circle_selection.cpp:14:10: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
circle_selection.cpp:14:10: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
circle_selection.cpp:14:10: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
#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...