Submission #710308

# Submission time Handle Problem Language Result Execution time Memory
710308 2023-03-15T06:59:00 Z vjudge1 Circle selection (APIO18_circle_selection) C++17
0 / 100
3000 ms 116192 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;

template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); } 
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);

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 <int> s;
set <pair<long double, int>> sd, sd1;
int ans[N];
bool f[N];
bool vis[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], e[N], d1[N], e1[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]);
}

inline void erase(int id){
    s.erase(id);
    sd.erase(e[id]);
    sd1.erase(e1[id]);
}
 
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};

        s.insert(i);
    }
    
    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);
        e[i] = d[i];

        d1[i].first = sdist(a[i], p4) + 10 * sdist(a[i], p3) + 100 * sdist(a[i], p2) + 1000 * sdist(a[i], p1);
        e1[i] = d1[i];
    }
    sort(d + 1, d + n + 1);
    sort(d1 + 1, d1 + n + 1);
    for(int i = 1; i <= n; ++i){
        sd.insert(d[i]);
        sd1.insert(d1[i]);
    }

    //dbg(e, 1, n);

    while (!s.empty()){
        int id = *s.begin();
        ans[id] = id;

        queue<int> q;
        vector <int> er;
        er.push_back(id);

        q.push(id);

        while (!q.empty()){

        auto itu = sd.find(e[q.front()]);
        q.pop();

        int ct = 0;
        auto it1 = itu;
        while (it1 != sd.begin()){
            --it1;
            int id2 = (*it1).second;

            if (ans[id2]){
                //++ct;
                continue;
            }

            if (isintersect(b[id], b[id2])){
                ans[id2] = id;
                er.push_back(id2);
                q.push(id2);
            } else ++ct;
            if (ct == 10) break;
        }
        ct = 0;
        auto it2 = itu;
        while (it2 != prev(sd.end())){
            ++it2;
            int id2 = (*it2).second;

            if (ans[id2]){
                //++ct;
                continue;
            }

            if (isintersect(b[id], b[id2])){
                ans[id2] = id;
                er.push_back(id2);
                q.push(id2);
            } else ++ct;
            if (ct == 10) break;
        }

        }

        q.push(id);

        while (!q.empty()){

        auto itu = sd1.find(e1[q.front()]);
        q.pop();

        int ct = 0;
        auto it1 = itu;
        while (it1 != sd1.begin()){
            --it1;
            int id2 = (*it1).second;

            if (ans[id2]){
                //++ct;
                continue;
            }

            if (isintersect(b[id], b[id2])){
                ans[id2] = id;
                er.push_back(id2);
                q.push(id2);
            } else ++ct;
            if (ct == 10) break;
        }
        ct = 0;
        auto it2 = itu;
        while (it2 != prev(sd1.end())){
            ++it2;
            int id2 = (*it2).second;

            if (ans[id2]){
                //++ct;
                continue;
            }

            if (isintersect(b[id], b[id2])){
                ans[id2] = id;
                er.push_back(id2);
                q.push(id2);
            } else ++ct;
            if (ct == 10) break;
        }

        }

        for(int i : er){
            erase(i);
        } er.clear();
    }
    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();
    }
}
# Verdict Execution time Memory 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 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3090 ms 116192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2029 ms 115048 KB Output is correct
2 Correct 1957 ms 115272 KB Output is correct
3 Incorrect 2007 ms 115180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -