답안 #757683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757683 2023-06-13T14:46:23 Z fanwen 원 고르기 (APIO18_circle_selection) C++17
38 / 100
1129 ms 42452 KB
/**
 *      author : pham van sam 
 *      created : 13 June 2023 (Tuesday)
 **/

#include <bits/stdc++.h>

using namespace std;
using namespace chrono;

#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

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3856 KB Output is correct
5 Correct 2 ms 3800 KB Output is correct
6 Incorrect 2 ms 3848 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 15140 KB Output is correct
2 Correct 171 ms 15176 KB Output is correct
3 Correct 164 ms 14968 KB Output is correct
4 Incorrect 206 ms 14868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 325 ms 17096 KB Output is correct
3 Correct 960 ms 42452 KB Output is correct
4 Correct 926 ms 42452 KB Output is correct
5 Correct 882 ms 37960 KB Output is correct
6 Correct 304 ms 20768 KB Output is correct
7 Correct 122 ms 12968 KB Output is correct
8 Correct 23 ms 5716 KB Output is correct
9 Correct 1129 ms 41836 KB Output is correct
10 Correct 698 ms 37224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 683 ms 42208 KB Output is correct
2 Correct 695 ms 41404 KB Output is correct
3 Correct 332 ms 24892 KB Output is correct
4 Correct 670 ms 41836 KB Output is correct
5 Correct 711 ms 41964 KB Output is correct
6 Correct 189 ms 19692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3856 KB Output is correct
5 Correct 2 ms 3800 KB Output is correct
6 Incorrect 2 ms 3848 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3856 KB Output is correct
5 Correct 2 ms 3800 KB Output is correct
6 Incorrect 2 ms 3848 KB Output isn't correct
7 Halted 0 ms 0 KB -