제출 #516775

#제출 시각아이디문제언어결과실행 시간메모리
516775pragmatist원 고르기 (APIO18_circle_selection)C++17
7 / 100
3083 ms36784 KiB
#include <bits/stdc++.h> #define sz(v) v.size() #define pb push_back #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define x first #define y second #define int long long #define nl "\n" using namespace std; typedef long long ll; typedef pair<long long, long long> pll; typedef pair <ll, ll> pii; const int N = (int)3e5 + 7; const int M = (int)15e6 + 7; const ll MOD = (ll)1e9 + 7; const int inf = (ll)1e9 + 7; const ll INF = (ll)3e18 + 7; pii dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; int n, x[N], y[N], c[N], a[N]; bool used[N]; bool intersect(int i, int j) { int d = c[i] + c[j]; d *= d; int p = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]); return p <= d; } bool ok() { for(int i = 1; i <= n; ++i) if(!used[i]) return 0; return 1; } void solve() { cin >> n; for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i] >> c[i]; if(n <= 5000) { while(!ok()) { int id = 0; for(int i = 1; i <= n; ++i) if(!used[i] && c[i] > c[id]) id = i; for(int i = 1; i <= n; ++i) { if(!used[i] && intersect(i, id)) a[i] = id, used[i] = 1; } } } else { set<pii> s; for(int i = 1; i <= n; ++i) s.insert({c[i], i}); while(!s.empty()) { int i = (*s.rbegin()).y; s.erase({c[i], i}); a[i] = i; vector<pii> v; for(auto [t, j] : s) { if(intersect(i, j)) { v.pb({t, j}); a[j] = i; } } for(auto e : v) s.erase(e); } } for(int i = 1; i <= n; ++i) cout << a[i] << ' '; } signed main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int test = 1; //cin >> test; for(int i = 1; i <= test; ++i) { //cout << "Case " << i << ": "; solve(); } return 0; } /* 11 9 9 2 13 2 1 11 8 2 3 3 2 3 12 1 12 14 1 9 8 5 2 8 2 5 2 1 14 4 2 14 14 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...