Submission #757685

#TimeUsernameProblemLanguageResultExecution timeMemory
757685fanwenCircle selection (APIO18_circle_selection)C++17
38 / 100
1010 ms40388 KiB
/** * author : pham van sam * created : 13 June 2023 (Tuesday) **/ #include <bits/stdc++.h> using namespace std; using namespace chrono; #define int long long #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it) template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; } template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; } const int MAXN = 3e5 + 5; int N, ans[MAXN], ID[MAXN]; long long sqr(long long x) { return x * x; } struct Circle_t { int x, y, r; // coordinate and radius Circle_t (int x = 0, int y = 0, int r = 0) : x(x), y(y), r(r) {} bool intersect(const Circle_t &a) const { return sqr(x - a.x) + sqr(y - a.y) <= sqr(r + a.r); } } a[MAXN]; const int MAX = 1e9, INF = 2e9 + 7; unordered_map <long long, vector <int>> mp; void rescaling_grid(int sz) { mp.clear(); FOR(i, 1, N) if(ans[i] == 0) { int x = a[i].x / sz, y = a[i].y / sz; long long tmp = 1LL * x * INF + y; mp[tmp].push_back(i); } } void eliminator(long long pos, int u) { if(!mp.count(pos)) return; vector <int> &points = mp[pos]; for (int i = 0; i < (int) points.size(); ++i) { if(a[points[i]].intersect(a[u])) { ans[points[i]] = u; swap(points[i--], points.back()); points.pop_back(); } } if(points.empty()) mp.erase(pos); } void process(void) { cin >> N; FOR(i, 1, N) { cin >> a[i].x >> a[i].y >> a[i].r; a[i].x += MAX; a[i].y += MAX; } iota(ID + 1, ID + N + 1, 1); sort(ID + 1, ID + N + 1, [&] (int i, int j) { return (a[i].r > a[j].r || (a[i].r == a[j].r && i < j)); }); int rMax = 1e9; FOR(i, 1, N) { int u = ID[i]; if(ans[u]) continue; if(a[u].r < rMax / 2) { rMax = a[u].r; rescaling_grid(rMax); } FOR(cx, a[u].x / rMax - 2, a[u].x / rMax + 2) { FOR(cy, a[u].y / rMax - 2, a[u].y / rMax + 2) { eliminator(1LL * cx * INF + cy, u); } } } FOR(i, 1, N) cout << ans[i] << " \n"[i == N]; } signed main() { #define TASK "TASK" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start_time = steady_clock::now(); int test = 1; // cin >> test; for (int i = 1; i <= test; ++i) { process(); // cout << '\n'; } auto end_time = steady_clock::now(); cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); }

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...