Submission #989998

# Submission time Handle Problem Language Result Execution time Memory
989998 2024-05-29T10:44:11 Z AlperenT_ Park (BOI16_park) C++17
100 / 100
376 ms 63380 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i , a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn =2e5+10  ,  N = 1e5 +1 , lg = 20 , maxq = 202   , inf = 1e18  , maxk = 2022  , mod =998244353;
int par[maxn] , dis[maxn] ,x[maxn] ,y[maxn] ,n , m , h ,w , r[maxn] ;
vector <pii>G[maxn] ;
int find(int v){
    if(par[v] == -1)return v;
    return par[v] = find(par[v]) ;
}

void dfs(int v, int p =-1){
    for(auto [u,w]: G[v]){
        if(u == p)continue ;
        dis[u]= max(w , dis[v]) ;
        dfs(u , v);
    }
}

int cal(int v ,int u){
    rep(i , 0 ,n+4){
        dis[i] = -inf ;
    }
    dis[v] = 0;
    dfs(v);
    return dis[u] ;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m >> w >> h;
    rep(i ,0 ,n-1){
        cin >> x[i] >> y[i] >> r[i] ;
    }
    rep(i , 0 , n+3){
        par[i] = -1 ;
    }
    vector<pair<int,pii> > vec;
    rep(i ,0 ,n-1){
        rep(j , i+1 , n-1){
            int f = abs(x[i]-x[j])*abs(x[i]-x[j]) +abs(y[i]-y[j])*abs(y[i]-y[j])  ;
            int L = 0 ,R = 2e9 ;
            while(R-L>1){
                int mid = (L+R)/2 ;
                if(mid*mid <= f){
                    L = mid ;
                }else{
                    R = mid ;
                }
            } 
            vec.pb({L-r[i]-r[j] , {i,j}}) ;
        }
    }
    rep(i ,0, n-1){
        vec.pb({x[i]-r[i] , {i , n+3}});
        vec.pb({w-x[i]-r[i] , {i , n+1}});
        vec.pb({y[i]-r[i] , {i , n}});
        vec.pb({h-y[i]-r[i], {i , n+2}});
    }
    sort(all(vec));
    rep(i , 0 ,sz(vec)-1){
        int w= vec[i].F, v = vec[i].S.F,  u = vec[i].S.S ;
        if(find(v) == find(u))continue ;
        G[v].pb({u,w});
        G[u].pb({v,w});
        par[find(v)] = find(u) ;
    }
    int d[4][4];
    rep(i , 0 , 3){
        rep(j , 0 , 3){
            if(i == j)continue ;
            d[i][j] = cal(n+i , n+j) ;
        }
    }
    while(m--){
        int r , t ;
        cin >> r >> t ;t--;
        string ans ;
        rep(i , 0 , 3){
            if(i == t){
                ans += (char)((i+1)+'0');
                continue ;
            }
            vector <int> a, b ;
            int x = t , y = i ;
            while(x != y){
                a.pb(x);
                x = (x+1)%4;
            }
            x = i ,y = t ;
            while(x!=y){
                b.pb(x);
                x = (x+1)%4 ;
            }
            bool ok =0 ;
            rep(j , 0, sz(a)-1){
                rep(k , 0 ,sz(b)-1){
                    if(d[a[j]][b[k]] < 2*r){
                        ok =1 ;
                    }
                }
            }
            if(ok == 0){
                ans += (char)((i+1)+'0') ;
            }
        }
        cout << ans << "\n"; 
    }
}

/*
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
*/
# Verdict Execution time Memory Grader output
1 Correct 336 ms 61640 KB Output is correct
2 Correct 337 ms 60836 KB Output is correct
3 Correct 334 ms 61000 KB Output is correct
4 Correct 337 ms 61092 KB Output is correct
5 Correct 333 ms 60324 KB Output is correct
6 Correct 339 ms 60768 KB Output is correct
7 Correct 322 ms 60840 KB Output is correct
8 Correct 315 ms 61084 KB Output is correct
9 Correct 2 ms 12888 KB Output is correct
10 Correct 2 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 14936 KB Output is correct
2 Correct 43 ms 14788 KB Output is correct
3 Correct 47 ms 14796 KB Output is correct
4 Correct 44 ms 14836 KB Output is correct
5 Correct 42 ms 14796 KB Output is correct
6 Correct 43 ms 14788 KB Output is correct
7 Correct 44 ms 14168 KB Output is correct
8 Correct 39 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 61640 KB Output is correct
2 Correct 337 ms 60836 KB Output is correct
3 Correct 334 ms 61000 KB Output is correct
4 Correct 337 ms 61092 KB Output is correct
5 Correct 333 ms 60324 KB Output is correct
6 Correct 339 ms 60768 KB Output is correct
7 Correct 322 ms 60840 KB Output is correct
8 Correct 315 ms 61084 KB Output is correct
9 Correct 2 ms 12888 KB Output is correct
10 Correct 2 ms 13148 KB Output is correct
11 Correct 48 ms 14936 KB Output is correct
12 Correct 43 ms 14788 KB Output is correct
13 Correct 47 ms 14796 KB Output is correct
14 Correct 44 ms 14836 KB Output is correct
15 Correct 42 ms 14796 KB Output is correct
16 Correct 43 ms 14788 KB Output is correct
17 Correct 44 ms 14168 KB Output is correct
18 Correct 39 ms 14164 KB Output is correct
19 Correct 373 ms 62620 KB Output is correct
20 Correct 374 ms 61716 KB Output is correct
21 Correct 370 ms 61600 KB Output is correct
22 Correct 371 ms 61852 KB Output is correct
23 Correct 376 ms 63380 KB Output is correct
24 Correct 352 ms 62748 KB Output is correct