Submission #172309

#TimeUsernameProblemLanguageResultExecution timeMemory
172309eggag32Circle selection (APIO18_circle_selection)C++17
7 / 100
643 ms42264 KiB
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl; #define debug2(x, y) debug(x) debug(y); #define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(i, a) for(int i = 0; i < (int)(a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define sq(x) ((x) * (x)) template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); } bool cmp(pair<pair<ld, int>, pair<ld, ld>> a, pair<pair<ld, int>, pair<ld, ld>> b){ if(a.fi.fi != b.fi.fi) return (a.fi.fi > b.fi.fi); return (a.fi.se < b.fi.se); } bool cmp1(pair<pair<ld, int>, pair<ld, ld>> a, pair<pair<ld, int>, pair<ld, ld>> b){ return (a.fi.fi < b.fi.fi); } bool cmp2(pair<pair<ld, int>, pair<ld, ld>> a, pair<pair<ld, int>, pair<ld, ld>> b){ return (a.fi.se < b.fi.se); } ld dist(ld x, ld y, ld x1, ld y1){ return sqrtl(sq(x1 - x) + sq(y1 - y)); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("input.in", "r", stdin); //freopen("output.out", "w", stdout); int n; cin >> n; vector<pair<pair<ld, int>, pair<ld, ld>>> c(n); int yis0 = 1; rep(i, n){ cin >> c[i].se.fi >> c[i].se.se >> c[i].fi.fi; if(c[i].se.se != 0) yis0 = 0; c[i].fi.se = i; } sort(all(c), cmp); if(n <= 5000){ vi vis(n, 0); vi ans(n, 0); //they are sorted in the way they appear rep(i, n) if(!vis[i]){ repn(j, i + 1, n) if(!vis[j]){ if(dist(c[i].se.fi, c[i].se.se, c[j].se.fi, c[j].se.se) <= (c[i].fi.fi + c[j].fi.fi)){ //they intersect vis[j] = 1; ans[c[j].fi.se] = c[i].fi.se; } } vis[i] = 1; ans[c[i].fi.se] = c[i].fi.se; } rep(i, n) cout << ans[i] + 1 << " "; cout << endl; return 0; } /* else if(yis0){ //well, I only got as far as so as putting all endpoints in a vector, so //not that far, but I got something } */ else{ //sort them by y and by x, for each circle, when you find //some other circle it intersects, they are both deleted by the //one with the larger r[i], or minimum i in case of a tie vector<pair<pair<ld, int>, pair<ld, ld>>> c1 = c; sort(all(c1), cmp1); //sort by x vi vis(n, 0); vi ans(n, -1); rep(i, c1.size() - 1){ if(dist(c1[i].se.fi, c1[i].se.se, c1[i + 1].se.fi, c1[i + 1].se.se) <= (c1[i].fi.fi + c1[i + 1].fi.fi)){ int best = i; if(c1[i].fi.fi < c1[i + 1].fi.fi) best = i + 1; else if(c1[i].fi.fi == c1[i + 1].fi.fi){ if(c1[i].fi.se > c1[i + 1].fi.se) best = i + 1; } ans[c1[i].fi.se] = best; ans[c1[i + 1].fi.se] = best; } } c1 = c; sort(all(c1), cmp1); //sort by y rep(i, c1.size() - 1){ if(dist(c1[i].se.fi, c1[i].se.se, c1[i + 1].se.fi, c1[i + 1].se.se) <= (c1[i].fi.fi + c1[i + 1].fi.fi)){ int best = i; if(c1[i].fi.fi < c1[i + 1].fi.fi) best = i + 1; else if(c1[i].fi.fi == c1[i + 1].fi.fi){ if(c1[i].fi.se > c1[i + 1].fi.se) best = i + 1; } ans[c1[i].fi.se] = best; ans[c1[i + 1].fi.se] = best; } } rep(i, ans.size()){ if(ans[i] == -1) ans[i] = i; cout << ans[i] + 1 << " "; } cout << endl; } return 0; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:49:6: warning: variable 'yis0' set but not used [-Wunused-but-set-variable]
  int yis0 = 1;
      ^~~~
#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...