Submission #313066

# Submission time Handle Problem Language Result Execution time Memory
313066 2020-10-15T07:04:32 Z mohamedsobhi777 Park (BOI16_park) C++14
100 / 100
594 ms 242512 KB
#include<bits/stdc++.h>

#define I inline void 
#define S struct 
#define vi vector<int> 
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std ; 
using ll = long long ; 
using ld = long double ; 

const int N = 5e6 + 7 , mod = 1e9 + 7 ; 
const int inf = N ; 
// How interesting!

int n, m; 
int w, h ; 
vector< pair<double,pii> > all ; 
double tx[N],ty[N],tr[N] ; 

int fat[N] ; 

inline int find(int x){return fat[x] = (x == fat[x] ? x : find(fat[x])) ; }
inline bool same(int x, int y){return find(x) == find(y) ; }

void link(int u , int v){
        u = find(u) ;
        v = find(v) ; 
        if(u!=v)fat[u] = v ; 
}

string ans[N] ; 

int main(){

        ios_base::sync_with_stdio(0) ;
        cin.tie(0) ; 
        //freopen("in.in" , "r" , stdin) ; 

        cin >> n >> m; 
        cin >> w >> h ;
        for(int i = 0 ;i < N ; ++ i)fat[i] = i ; 
        for(int i = 0 ;i < n; ++ i){
                cin >> tx[i] >> ty[i] >> tr[i] ; 
                for(int j = 0 ;j < i ;++ j){
                        double d = hypot(tx[i] - tx[j] , ty[i] - ty[j]) - tr[i] - tr[j] ; 
                        all.push_back({d , {i , j} }) ; 
                }
                all.push_back({ty[i] - tr[i] , {i , n + 1}}) ; 
                all.push_back({tx[i] - tr[i] , {i , n + 2}}) ; 
                all.push_back({w - tx[i] - tr[i] , {i , n + 3}}) ; 
                all.push_back({h - ty[i] - tr[i] , {i , n + 4}}) ; 
        } 

        for(int i = 1 ;i <= m ;++ i){
                double r ;
                int e ;
                cin >> r >> e ;
                all.push_back({r * 2 , { - i , e} }) ; 
        }
        sort(all.begin() , all.end()) ; 
        for(auto u : all){
                if(u.second.first < 0){
                        int j = -(u.second.first + 1) ; 
                        int ant = u.second.second ; 
                        if(same(n + 1 , n + 4) && same(n + 2 , n + 3) ){
                                ans[j] = char('0' + ant) ; 
                        }
                        else if(same(n + 1, n + 4) ){
                                if(ant == 1 || ant == 4){
                                        if(!same(n + 1, n + 2) && !same(n + 2, n + 4)){
                                                ans[j] = "14" ; 
                                        }else ans[j] = char('0' + ant) ; 
                                }else{
                                        if(!same(n + 1, n + 3) && ! same(n + 3 , n + 4)){
                                                ans[j] = "23" ; 
                                        }else ans[j] = char('0' + ant) ; 
                                }
                        }else if(same(n + 2 , n + 3)){
                                if(ant == 1 || ant == 2){
                                        if(!same(n + 1 , n + 2) && !same(n + 1 , n + 3)){
                                                ans[j] = "12" ; 
                                        }else ans[j] = char('0' + ant) ; 
                                }else{
                                        if(!same(n + 2 , n + 4) && !same(n + 3, n + 4)){
                                                ans[j] = "34" ; 
                                        }else ans[j] = char('0' + ant) ; 
                                }
                        }else{
                                vector<int> ok(5 , 1) ; 
                                if(same(n + 1 , n + 2))ok[1] = 0 ; 
                                if(same(n + 1 , n + 3))ok[2] = 0 ; 
                                if(same(n + 3 , n + 4))ok[3] = 0 ; 
                                if(same(n + 2 , n + 4))ok[4] = 0 ; 
                                for(int k = 1; k<= 4 ;++ k){
                                        if((ok[ant] && ok[k]) || ant == k)
                                                ans[j] += char('0' + k) ; 
                                } 
                        }
                }else{
                        link(u.second.first ,u.second.second) ;
                }
        }
        for(int i = 0 ;i < m; ++ i){
                cout<< ans[i] <<"\n" ;
        }

        return 0 ; 
}
# Verdict Execution time Memory Grader output
1 Correct 500 ms 209624 KB Output is correct
2 Correct 505 ms 209488 KB Output is correct
3 Correct 503 ms 209604 KB Output is correct
4 Correct 513 ms 209588 KB Output is correct
5 Correct 508 ms 209472 KB Output is correct
6 Correct 509 ms 209472 KB Output is correct
7 Correct 435 ms 209448 KB Output is correct
8 Correct 435 ms 209656 KB Output is correct
9 Correct 120 ms 176632 KB Output is correct
10 Correct 115 ms 176504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 178928 KB Output is correct
2 Correct 192 ms 178928 KB Output is correct
3 Correct 183 ms 178924 KB Output is correct
4 Correct 185 ms 178916 KB Output is correct
5 Correct 190 ms 178920 KB Output is correct
6 Correct 188 ms 178924 KB Output is correct
7 Correct 182 ms 178676 KB Output is correct
8 Correct 183 ms 178800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 209624 KB Output is correct
2 Correct 505 ms 209488 KB Output is correct
3 Correct 503 ms 209604 KB Output is correct
4 Correct 513 ms 209588 KB Output is correct
5 Correct 508 ms 209472 KB Output is correct
6 Correct 509 ms 209472 KB Output is correct
7 Correct 435 ms 209448 KB Output is correct
8 Correct 435 ms 209656 KB Output is correct
9 Correct 120 ms 176632 KB Output is correct
10 Correct 115 ms 176504 KB Output is correct
11 Correct 193 ms 178928 KB Output is correct
12 Correct 192 ms 178928 KB Output is correct
13 Correct 183 ms 178924 KB Output is correct
14 Correct 185 ms 178916 KB Output is correct
15 Correct 190 ms 178920 KB Output is correct
16 Correct 188 ms 178924 KB Output is correct
17 Correct 182 ms 178676 KB Output is correct
18 Correct 183 ms 178800 KB Output is correct
19 Correct 594 ms 242408 KB Output is correct
20 Correct 590 ms 242332 KB Output is correct
21 Correct 594 ms 242476 KB Output is correct
22 Correct 588 ms 242356 KB Output is correct
23 Correct 590 ms 242512 KB Output is correct
24 Correct 529 ms 242336 KB Output is correct