답안 #670760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670760 2022-12-10T09:42:28 Z berr Park (BOI16_park) C++17
100 / 100
1799 ms 1824 KB
#include <bits/stdc++.h>
using namespace std;   
#define int long long 
vector<int> tx(2005), ty(2005), tr(2005), vis(2005);
int dist[4][4], x, y;
queue<int> q;
 
int check(int a, int b, int s){
    int h=(tx[a]-tx[b]);
    int e=(ty[a]-ty[b]);
    h*=h; e*=e;
 
    h+=e;
 
    int f=2*s+tr[a]+tr[b];
    
    if((f*f)>h) return 1;
    return 0;
 
}

int down(int a, int tmp){
    tmp*=2;
    if((ty[a]-tr[a])<tmp) return 1;
    return 0;
}
int up(int a, int tmp){
    tmp*=2;
    if((y-(ty[a]+tr[a]))<tmp) return 1;
    return 0;
}

int left(int a, int tmp){
    tmp*=2;
    if((tx[a]-tr[a])<tmp) return 1;
    return 0;
}


int right(int a, int tmp){
    tmp*=2;
    if((x-(tx[a]+tr[a]))<tmp) return 1;
    return 0;
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
        
 
    int n, m; cin >> n >> m;
 
     cin >> x >> y;
 
    for(int i=0; i<n; i++){
        cin>>tx[i]>>ty[i]>>tr[i];
    }
 
    int s=0;
    //l u
    for(int i=30; i>=0; i--){
        int tmp = s+(1<<i);
 
        for(int l=0; l<n; l++){
            vis[l]=0;
            if(left(l, tmp)) q.push(l), vis[l]=1;
            
        }
 
        while(q.size()){
            int v=q.front(); q.pop();
 
            for(int l=0; l<n; l++){
                if(!vis[l]&&check(l, v, tmp)){
                    vis[l]=1; q.push(l);
                }
            }
        }
 
        int flag=1;
 
        for(int l=0; l<n; l++){
            if(!vis[l]) continue;
 
            if(up(l, tmp)) flag=0;
        }
 
        if(flag) s=tmp;
    }
 
    dist[0][1]=dist[1][0]=s;
 
    s=0;
    // l, r;
    for(int i=30; i>=0; i--){
        int tmp = s+(1<<i);
 
        for(int l=0; l<n; l++){
            vis[l]=0;
            if(left(l, tmp)) q.push(l), vis[l]=1;
        }
 
        while(q.size()){
            int v=q.front(); q.pop();
 
            for(int l=0; l<n; l++){
                if(!vis[l]&&check(l, v, tmp)){
                    vis[l]=1; q.push(l);
                }
            }
        }
 
        int flag=1;
        for(int l=0; l<n; l++){
            if(!vis[l]) continue;
 
            if(right(l, tmp)) flag=0;
        }
 
        if(flag) s=tmp;
    }
    dist[0][2]=dist[2][0]=s;
 
    s=0;
    //l, d
    for(int i=30; i>=0; i--){
        int tmp = s+(1<<i);
 
        for(int l=0; l<n; l++){
            vis[l]=0;
            if(left(l, tmp)) q.push(l), vis[l]=1;
            
        }
 
        while(q.size()){
            int v=q.front(); q.pop();
 
            for(int l=0; l<n; l++){
                if(!vis[l]&&check(l, v, tmp)){
                    vis[l]=1; q.push(l);
                }
            }
        }
 
        int flag=1;
        for(int l=0; l<n; l++){
            if(!vis[l]) continue;
 
            if(down(l, tmp)) flag=0;
        }
 
        if(flag) s=tmp;
    }
    dist[0][3]=dist[3][0]=s;
 
    s=0;
    //u, r
    for(int i=30; i>=0; i--){
        int tmp = s+(1<<i);
 
        for(int l=0; l<n; l++){
            vis[l]=0;
            if(up(l, tmp)) q.push(l), vis[l]=1;
            
        }
 
        while(q.size()){
            int v=q.front(); q.pop();
 
            for(int l=0; l<n; l++){
                if(!vis[l]&&check(l, v, tmp)){
                    vis[l]=1; q.push(l);
                }
            }
        }
 
        int flag=1;
        for(int l=0; l<n; l++){
            if(!vis[l]) continue;
 
            if(right(l, tmp)) flag=0;
        }
 
        if(flag) s=tmp;
    }
 
    dist[1][2]=dist[2][1]=s;
    
    s=0;
    //u, d
    for(int i=30; i>=0; i--){
        int tmp = s+(1<<i);
 
        for(int l=0; l<n; l++){
            vis[l]=0;
            if(up(l, tmp)) q.push(l), vis[l]=1;
            
        }   
 
        while(q.size()){
            int v=q.front(); q.pop();
 
            for(int l=0; l<n; l++){
                if(!vis[l]&&check(l, v, tmp)){
                    vis[l]=1;
                    q.push(l);
                }
            }
        }
 
        int flag=1;
        for(int l=0; l<n; l++){
            if(!vis[l]) continue;
 
            if(down(l, tmp)) flag=0;
        }
        
        if(flag) s=tmp;
    }
    dist[1][3]=dist[3][1]=s;
 
    s=0;
    // r, d;
    for(int i=30; i>=0; i--){
        int tmp = s+(1<<i);
 
        for(int l=0; l<n; l++){
            vis[l]=0;
            if(right(l, tmp)) q.push(l), vis[l]=1;
            
        }
 
        while(q.size()){
            int v=q.front(); q.pop();
 
            for(int l=0; l<n; l++){
                if(!vis[l]&&check(l, v, tmp)){
                    vis[l]=1; q.push(l);
                }
            }
        }
 
        int flag=1;
        for(int l=0; l<n; l++){
            if(!vis[l]) continue;
 
            if(down(l, tmp)) flag=0;
        }
 
        if(flag) s=tmp;
    }
    dist[2][3]=dist[3][2]=s;
 
 
    for(int i=0; i<m; i++)
    {
        int t, s; cin>>s>>t;
        string ans;
        if(t==1){
            ans+='1';
            if(min({dist[0][3], dist[1][3], dist[2][3]})>=s) ans+='2';
            if(min({dist[0][2], dist[0][3], dist[1][3], dist[1][2]})>=s) ans+='3';
            if(min({dist[0][3], dist[0][2], dist[0][1]})>=s) ans+='4';
 
        }
 
        if(t==2){
            if(min({dist[0][3], dist[1][3], dist[2][3]})>=s) ans+='1';
            ans+='2';
            if(min({dist[2][1], dist[2][3], dist[2][0]})>=s) ans+='3';
            if(min({dist[0][1], dist[0][2], dist[1][3], dist[2][3]})>=s) ans+='4';
 
        }
        if(t==3){
            if(min({dist[0][2], dist[0][3], dist[1][3], dist[1][2]})>=s) ans+='1';
            if(min({dist[2][1], dist[2][3], dist[2][0]})>=s) ans+='2';
            ans+='3';
            if(min({dist[1][3], dist[1][2], dist[1][0]})>=s) ans+='4';
 
        }
        if(t==4){
            if(min({dist[0][3], dist[0][2], dist[0][1]})>=s) ans+='1';
            if(min({dist[0][1], dist[0][2], dist[1][3], dist[2][3]})>=s) ans+='2';
            if(min({dist[1][3], dist[1][2], dist[1][0]})>=s) ans+='3';
            ans+='4';
        }
 
        cout<<ans<<"\n";
 
    }
 
 
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1784 ms 380 KB Output is correct
2 Correct 1703 ms 376 KB Output is correct
3 Correct 1350 ms 384 KB Output is correct
4 Correct 1508 ms 376 KB Output is correct
5 Correct 1529 ms 384 KB Output is correct
6 Correct 1255 ms 384 KB Output is correct
7 Correct 1724 ms 380 KB Output is correct
8 Correct 1799 ms 380 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 796 KB Output is correct
2 Correct 38 ms 616 KB Output is correct
3 Correct 40 ms 588 KB Output is correct
4 Correct 38 ms 584 KB Output is correct
5 Correct 35 ms 648 KB Output is correct
6 Correct 42 ms 1700 KB Output is correct
7 Correct 22 ms 1824 KB Output is correct
8 Correct 23 ms 1724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1784 ms 380 KB Output is correct
2 Correct 1703 ms 376 KB Output is correct
3 Correct 1350 ms 384 KB Output is correct
4 Correct 1508 ms 376 KB Output is correct
5 Correct 1529 ms 384 KB Output is correct
6 Correct 1255 ms 384 KB Output is correct
7 Correct 1724 ms 380 KB Output is correct
8 Correct 1799 ms 380 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 36 ms 796 KB Output is correct
12 Correct 38 ms 616 KB Output is correct
13 Correct 40 ms 588 KB Output is correct
14 Correct 38 ms 584 KB Output is correct
15 Correct 35 ms 648 KB Output is correct
16 Correct 42 ms 1700 KB Output is correct
17 Correct 22 ms 1824 KB Output is correct
18 Correct 23 ms 1724 KB Output is correct
19 Correct 1542 ms 1668 KB Output is correct
20 Correct 1533 ms 1644 KB Output is correct
21 Correct 1327 ms 1772 KB Output is correct
22 Correct 1091 ms 1688 KB Output is correct
23 Correct 1395 ms 1620 KB Output is correct
24 Correct 1799 ms 1776 KB Output is correct