제출 #1261703

#제출 시각아이디문제언어결과실행 시간메모리
12617034QT0R원 고르기 (APIO18_circle_selection)C++20
49 / 100
3138 ms877888 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long ll n; vector<array<ll, 3>> info; map<pair<ll, ll>, unordered_set<ll>> mp; vector<ll> ans; vector<bool> del; ll grid_length; ll sq(ll x) { return x * x; } bool query(ll i, ll j) { return (sq(info[i][0] - info[j][0]) + sq(info[i][1] - info[j][1])) <= sq(info[i][2] + info[j][2]); } void remake() { mp.clear(); for (ll i = 0; i < n; i++) { if (del[i]) continue; mp[{info[i][0] / grid_length, info[i][1] / grid_length}].insert(i); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; ans.resize(n); del.resize(n); for (ll i = 1, x, y, r; i <= n; i++) { cin >> x >> y >> r; info.push_back({x, y, r}); } vector<ll> kol(n); iota(kol.begin(), kol.end(), 0); sort(kol.begin(), kol.end(), [&](ll a, ll b) { return info[a][2] == info[b][2] ? a < b : info[a][2] > info[b][2]; }); grid_length = info[kol[0]][2]; remake(); for (auto now : kol) { if (del[now]) continue; if (2 * info[now][2] <= grid_length) { grid_length = info[now][2]; remake(); } ll cur_x = info[now][0] / grid_length; ll cur_y = info[now][1] / grid_length; vector<ll> deleted_now; for (ll x = -2; x <= 2; x++) { for (ll y = -2; y <= 2; y++) { for (auto ind : mp[{cur_x + x, cur_y + y}]) { if (query(now, ind)) deleted_now.push_back(ind); } } } while (deleted_now.size()) { ll ind = deleted_now.back(); deleted_now.pop_back(); del[ind] = true; mp[{info[ind][0] / grid_length, info[ind][1] / grid_length}].erase(ind); ans[ind] = now; } } for (auto x : ans) cout << x+1 << ' '; cout << '\n'; }
#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...