답안 #710109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710109 2023-03-15T04:45:05 Z vjudge1 원 고르기 (APIO18_circle_selection) C++17
0 / 100
1396 ms 44556 KB
/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/

#include <bits/stdc++.h>
#define endl '\n'

#define int long long

using namespace std;

const int N = 3e5 + 5;
const long long INF = 1e18 + 7;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;

array<int, 3> b[N];
set <array<int, 3>> s;
int ans[N];
bool f[N];

struct point{
    int x, y;
 
    bool operator <(const point& p) const{
        return x < p.x || (x == p.x && y < p.y);
    }
    
    bool operator >(const point& p) const{
        return x > p.x || (x == p.x && y > p.y);
    }
} a[N];
 
pair<long double, int> d[N];
 
inline int dist(point a, point b){
    int h1 = a.x - b.x;
    int h2 = a.y - b.y;
 
    return h1 * h1 + h2 * h2;
}
 
inline long double sdist(point a, point b){
    return sqrt(dist(a, b));
}

bool isintersect(array<int, 3> a, array<int, 3> b){
    point a1, b1;
    a1.x = a[0]; a1.y = a[1];
    b1.x = b[0]; b1.y = b[1];
    return dist(a1, b1) <= (a[2] + b[2]) * (a[2] + b[2]);
}

void tryshit(){
    array<int, 3> last = {-INF, -INF, -INF};
    int sz = s.size();
    for(int i = 1; i <= sz; ++i){
        auto it = s.upper_bound(last);
        if (it == s.end()) break;
        array<int, 3> state = *it;
        int id = state[2];

        last = state;

        int ct = 0;
        auto it2 = it;
        while(1){
            ++it2; ++ct;
            if (it2 == s.end()) break;
            int i = (*it2)[2];
            if (!ans[i]){
                if (isintersect(b[i], b[id])){
                    s.erase(state);
                    ans[i] = id; ans[id] = id;
                    s.erase({-b[i][2], b[i][2], i});
                    break;
                }
            }
            if (ct == 20) break;
        }

        auto it3 = s.end();
        ct = 0;
        while(1){
            --it3; ++ct;
            if (it3 == it) break;
            int i = (*it3)[2];
            if (!ans[i]){
                if (isintersect(b[i], b[id])){
                    s.erase(state);
                    ans[i] = id; ans[id] = id;
                    s.erase({-b[i][2], b[i][2], i});
                    break;
                }
            }
            if (ct == 20) break;
        }
    }
}
 
void solve(){
    int n; cin >> n;
    for(int i = 1; i <= n; ++i){
        int x, y, r; cin >> x >> y >> r;
        b[i] = {x, y, r};
        a[i] = {x, y};
    }
    
    point p1 = a[1], p2 = a[1];
    point p3 = {a[1].y, a[1].x}, p4 = {a[1].y, a[1].x};
 
    for(int i = 1; i <= n; ++i){
        p1 = min(p1, a[i]);
        p2 = max(p2, a[i]);
        p3 = min(p3, {a[1].y, a[1].x});
        p4 = max(p4, {a[1].y, a[1].x});
 
        d[i].second = i;
    }
    for(int i = 1; i <= n; ++i){
        d[i].first = sdist(a[i], p1) + 10 * sdist(a[i], p2) + 100 * sdist(a[i], p3) + 1000 * sdist(a[i], p4);
    }
    sort(d + 1, d + n + 1);
 
    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= min(n, i + 100); ++j){
            int idi = d[i].second, idj = d[j].second;
            if (isintersect(b[idi], b[idj])){
                if (b[idi][2] > b[idj][2] || (b[idi][2] == b[idj][2] && idi < idj)){
                    ans[idi] = ans[idj] = idi;
                } else {
                    ans[idi] = ans[idj] = idj;
                }
            }
        }
    }

    for(int i = 1; i <= n; ++i){
        if (!ans[i]) s.insert({-b[i][2], b[i][2], i});
    }

    for(int i = 1; i <= 5; ++i){
        tryshit();
    }

    for(int i = 1; i <= n; ++i){
        if (!ans[i]) ans[i] = i;
    }

    for(int i = 1; i <= n; ++i) cout << ans[i] << " "; 
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("codeforces.inp","r",stdin);
    // freopen("codeforces.out","w",stdout);

    int t = 1; // cin >> t;
    while (t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 333 ms 25696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 461 ms 14876 KB Output is correct
3 Correct 1364 ms 44556 KB Output is correct
4 Correct 1396 ms 44436 KB Output is correct
5 Incorrect 705 ms 33436 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 861 ms 44544 KB Output is correct
2 Correct 857 ms 44492 KB Output is correct
3 Incorrect 321 ms 27200 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -