Submission #274885

# Submission time Handle Problem Language Result Execution time Memory
274885 2020-08-19T19:57:46 Z rqi Park (BOI16_park) C++14
100 / 100
540 ms 35672 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long double ld;

#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(x) begin(x), end(x)

const int MOD = 1000000007;
const int mx = 100005;

int n, m;
ll w, h;
ll k;
ll x[mx];
ll y[mx];
ll r[mx];

ll R[mx];
int e[mx];

pair<vi, vi> sep[7];
pi connec[7];

int his[7]; //lowest value to make it connected

int E[mx];
void init(){
    for(int i = 1; i <= n+4; i++){
        E[i] = -1;
    }
}

int get(int a){
    if(E[a] < 0) return a;
    E[a] = get(E[a]);
    return E[a];
}

void unite(int a, int b){
    a = get(a);
    b = get(b);
    if(a == b) return;
    if(-E[a] < -E[b]) swap(a, b);
    E[a]+=E[b];
    E[b] = a;
}

// int comp[mx];
// vi adj[mx];

// void ae(int a, int b){
//     adj[a].pb(b); adj[b].pb(a);
// }

// void dfs(int node, int val){
//     if(comp[node] != 0) return;
//     comp[node] = val;
//     for(auto u: adj[node]){
//         dfs(u, val);
//     }
// }

// bool works(int ind, ll mid){
//     for(int i = 1; i <= n+4; i++){
//         comp[i] = 0;
//         adj[i].clear();
//     }

//     //add all the edges
//     for(int i = 1; i <= n; i++){
//         for(int j = i+1; j <= n; j++){
//             if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) < (r[i]+r[j]+2*mid)*(r[i]+r[j]+2*mid)){
//                 ae(i, j);
//             }
//         }
//     }

//     for(int i = 1; i <= n; i++){
//         ll xlo = x[i]-r[i]-2*mid;
//         ll xhi = x[i]+r[i]+2*mid;
//         ll ylo = y[i]-r[i]-2*mid;
//         ll yhi = y[i]+r[i]+2*mid;
//         if(xlo < 0){
//             ae(i, n+4);
//         }
//         if(xhi > w){
//             ae(i, n+2);
//         }
//         if(ylo < 0){
//             ae(i, n+1);
//         }
//         if(yhi > h){
//             ae(i, n+3);
//         }
//     }

//     for(int i = 1; i <= n+4; i++){
//         if(comp[i] != 0) continue;
//         dfs(i, i); //node, val
//     }

//     if(comp[connec[ind].f] == comp[connec[ind].s]) return 1;
//     return 0;
// }

// void findHis(){
//     for(int i = 1; i <= 6; i++){
//         ll lo = 0;
//         ll hi = MOD;
//         while(lo < hi){
//             ll mid = (lo+hi)/2;
//             if(works(i, mid)){
//                 hi = mid;
//             }
//             else lo = mid+1;
//         }
//         his[i] = lo;
//     }
// }

ll getSqrt(ll dist2, ll sum){
    if(dist2 == sum*sum) return 1;
    ld dist = sqrt(ld(dist2));
    dist-=ld(sum);
    dist/=ld(2);
    ll res = round(dist);
    while(res >= 1 && dist2 < (sum+2*(res-1))*(sum+2*(res-1))){
        res--;
    }
    while(dist2 >= (sum+2*res)*(sum+2*res)){
        res++;
    }
    return res;
}   

void findHis(){
    vector<pair<ll, pi>> eds;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            eds.pb(mp(getSqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]), r[i]+r[j]), mp(i, j)));
        }
    }

    for(int i = 1; i <= n; i++){
        ll xlo = x[i]-r[i];
        ll xhi = x[i]+r[i];
        ll ylo = y[i]-r[i];
        ll yhi = y[i]+r[i];
        eds.pb(mp((xlo-0)/2+1, mp(i, n+4)));
        eds.pb(mp((w-xhi)/2+1, mp(i, n+2)));
        eds.pb(mp((ylo-0)/2+1, mp(i, n+1)));
        eds.pb(mp((h-yhi)/2+1, mp(i, n+3)));
    }
    sort(all(eds));



    for(auto u: eds){
        unite(u.s.f, u.s.s);
        //cout << u.f << " " << u.s.f << " " << u.s.s << "\n";
        vi comps(5, 0);
        // for(int i = 1; i <= n+4; i++){
        //     cout << i << " " << E[i] << "\n";
        // }
        for(int j = 1; j <= 4; j++){
            comps[j] = get(n+j);
            //cout << j << " " << comps[j] << "\n";
        }
        for(int j = 1; j <= 6; j++){
            //cout << "HIS " << j << " " << his[j] << "\n";
            if(his[j] != -1) continue;
            if(comps[connec[j].f-n] == comps[connec[j].s-n]){
                his[j] = u.f;
                //cout << "HIS " << j << " " << his[j] << "\n";
            }
        }
    }
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    cin >> w >> h;

    init();

    for(int i = 1; i <= 6; i++){
        his[i] = -1;
    }
    sep[1] = mp(vi{1}, vi{2, 3, 4});
    sep[2] = mp(vi{2}, vi{1, 3, 4});
    sep[3] = mp(vi{3}, vi{1, 2, 4});
    sep[4] = mp(vi{4}, vi{1, 2, 3});
    sep[5] = mp(vi{1, 4}, vi{2, 3});
    sep[6] = mp(vi{1, 2}, vi{3, 4});
    connec[1] = mp(n+1, n+4);
    connec[2] = mp(n+1, n+2);
    connec[3] = mp(n+2, n+3);
    connec[4] = mp(n+3, n+4);
    connec[5] = mp(n+1, n+3);
    connec[6] = mp(n+2, n+4);

    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    for(int i = 1; i <= m; i++){
        cin >> R[i] >> e[i];
        k = max(k, r[i]);
    }

    findHis();

    for(int i = 1; i <= m; i++){
        vector<bool> v(5, true);
        for(int j = 1; j <= 6; j++){
            if(R[i] >= his[j]){
                for(auto u: sep[j].f){
                    if(u == e[i]){
                        for(auto z: sep[j].s){
                            v[z] = false;
                        }
                    }
                }
                for(auto u: sep[j].s){
                    if(u == e[i]){
                        for(auto z: sep[j].f){
                            v[z] = false;
                        }
                    }
                }
            }
        }
        for(int j = 1; j <= 4; j++){
            if(v[j] == true) cout << j;
        }
        cout << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 487 ms 33344 KB Output is correct
2 Correct 485 ms 33348 KB Output is correct
3 Correct 485 ms 33496 KB Output is correct
4 Correct 492 ms 33476 KB Output is correct
5 Correct 486 ms 33344 KB Output is correct
6 Correct 499 ms 33348 KB Output is correct
7 Correct 422 ms 33476 KB Output is correct
8 Correct 455 ms 33472 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2172 KB Output is correct
2 Correct 51 ms 2240 KB Output is correct
3 Correct 48 ms 2176 KB Output is correct
4 Correct 46 ms 2176 KB Output is correct
5 Correct 53 ms 2168 KB Output is correct
6 Correct 53 ms 2176 KB Output is correct
7 Correct 39 ms 1784 KB Output is correct
8 Correct 40 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 487 ms 33344 KB Output is correct
2 Correct 485 ms 33348 KB Output is correct
3 Correct 485 ms 33496 KB Output is correct
4 Correct 492 ms 33476 KB Output is correct
5 Correct 486 ms 33344 KB Output is correct
6 Correct 499 ms 33348 KB Output is correct
7 Correct 422 ms 33476 KB Output is correct
8 Correct 455 ms 33472 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 53 ms 2172 KB Output is correct
12 Correct 51 ms 2240 KB Output is correct
13 Correct 48 ms 2176 KB Output is correct
14 Correct 46 ms 2176 KB Output is correct
15 Correct 53 ms 2168 KB Output is correct
16 Correct 53 ms 2176 KB Output is correct
17 Correct 39 ms 1784 KB Output is correct
18 Correct 40 ms 1792 KB Output is correct
19 Correct 538 ms 35588 KB Output is correct
20 Correct 528 ms 35564 KB Output is correct
21 Correct 527 ms 35648 KB Output is correct
22 Correct 530 ms 35672 KB Output is correct
23 Correct 540 ms 35648 KB Output is correct
24 Correct 463 ms 35648 KB Output is correct