Submission #741174

#TimeUsernameProblemLanguageResultExecution timeMemory
741174speedyArdaCircle selection (APIO18_circle_selection)C++14
7 / 100
3053 ms22304 KiB
#include "bits/stdc++.h" #pragma GCC optimize ("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") using namespace std; const int MAXN = 3e5+5; vector< pair < pair<int, int>, pair<int, int> > > circles; vector<int> ans(MAXN, 0); bool cmp(pair < pair<int, int>, pair<int, int> > a, pair < pair<int, int>, pair<int, int> > b) { if(a.second.first != b.second.first) return a.second.first > b.second.first; return a.second.second < b.second.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; circles.push_back({{x, y}, {r, i}}); } sort(circles.begin(), circles.end(), cmp); if(n <= 5e3) { for(int i = 0; i < n; i++) { 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 i = 0; i < n; i++) { if(ans[circles[i].second.second] != 0) continue; 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) { if(circles[i].first.first - (*it).first <= circles[i].second.first + circles[(*it).second].second.first) { toerase.push_back((*it).second); } else break; if(it == elems.begin()) break; it--; } } it = prev; while(it != elems.end()) { if(abs(circles[i].first.first - (*it).first) <= circles[i].second.first + circles[(*it).second].second.first) { toerase.push_back((*it).second); } else break; it++; } for(int e : toerase) { ans[circles[e].second.second] = circles[i].second.second + 1; elems.erase({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:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("unroll-loops")
      |
#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...