제출 #701390

#제출 시각아이디문제언어결과실행 시간메모리
701390Abrar_Al_Samit원 고르기 (APIO18_circle_selection)C++17
0 / 100
602 ms28596 KiB
#include<bits/stdc++.h> using namespace std; long long sqrd(int x) { return x * 1LL * x; } struct circle { int x, y, r, j; bool operator< (const circle& b) const { if(r!=b.r) return r > b.r; return j < b.j; } bool intersect(const circle& b) const { return sqrd(x-b.x) + sqrd(y-b.y) <= sqrd(r+b.r); } }; bool cmp(circle a, circle b) { return make_pair(a.x, a.r) < make_pair(b.x, b.r); } void PlayGround() { int n; cin>>n; set<circle>s; for(int i=0; i<n; ++i) { int x, y, r; cin>>x>>y>>r; circle z = {x, y, r, i+1}; s.insert(z); } int at[n+1]; vector<circle>order; for(auto z : s) { order.push_back(z); } sort(order.begin(), order.end(), cmp); for(int i=0; i<n; ++i) { at[order[i].j] = i; } bool done[n+1] = {0}; int ans[n+1]; while(!s.empty()) { auto cur = *s.begin(); s.erase(cur); int p = at[cur.j]; while(p>=0 && !done[p] && cur.intersect(order[p])) { done[p] = true; ans[order[p].j] = cur.j; s.erase(order[p]); --p; } p = at[cur.j] + 1; while(p<n && !done[p] && cur.intersect(order[p])) { done[p] = true; ans[order[p].j] = cur.j; s.erase(order[p]); ++p; } } for(int i=1; i<=n; ++i) { cout<<ans[i]<<' '; } // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#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...