Submission #49427

#TimeUsernameProblemLanguageResultExecution timeMemory
49427gs13105Circle selection (APIO18_circle_selection)C++17
19 / 100
1210 ms38028 KiB
#include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <iterator> using namespace std; struct cir { int x, y, r, i; bool operator <(const cir &a) const { return r != a.r ? r > a.r : i < a.i; } }; cir arr[300010]; int num[300010]; int res[300010]; bool inter(const cir &a, const cir &b) { return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y) <= 1LL * (a.r + b.r) * (a.r + b.r); } int main() { //freopen("in", "r", stdin); //freopen("out", "w", stdout); int n, i, j; scanf("%d", &n); for(i = 1; i <= n; i++) { int x, y, r; scanf("%d%d%d", &x, &y, &r); arr[i] = { x, y, r, i }; } sort(arr + 1, arr + n + 1); if(n <= 5000) { for(i = 1; i <= n; i++) if(!num[i]) for(j = 1; j <= n; j++) if(!num[j] && inter(arr[i], arr[j])) num[j] = arr[i].i; for(i = 1; i <= n; i++) res[arr[i].i] = num[i]; for(i = 1; i <= n; i++) printf("%d ", res[i]); return 0; } bool st2 = 1; for(i = 1; i <= n; i++) { if(arr[i].y != 0) { st2 = 0; break; } } if(st2) { set<pair<int, int>> s; for(i = 1; i <= n; i++) { s.insert({ arr[i].x - arr[i].r, i }); s.insert({ arr[i].x + arr[i].r, i }); } for(i = 1; i <= n; i++) { if(num[i]) continue; auto it = s.lower_bound({ arr[i].x - arr[i].r, -1 }); while(it != s.end() && it->first <= arr[i].x + arr[i].r) { int x = it->second; if(!num[x]) num[x] = arr[i].i; it++; s.erase(prev(it)); } } for(i = 1; i <= n; i++) res[arr[i].i] = num[i]; for(i = 1; i <= n; i++) printf("%d ", res[i]); return 0; } return 0; }

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...