답안 #710064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710064 2023-03-15T04:18:05 Z vjudge1 원 고르기 (APIO18_circle_selection) C++17
0 / 100
259 ms 82216 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 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 + 10); ++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});
    }

    assert(s.size() <= 100);

    while (!s.empty()){
        array<int, 3> state = *s.begin();
        int id = state[2];

        s.erase(state);

        ans[id] = id;

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

    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 0 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 0 ms 340 KB Output is correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 179 ms 25868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 92 ms 28856 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 259 ms 82216 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -