답안 #987805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987805 2024-05-23T15:39:22 Z alexdd Park (BOI16_park) C++17
100 / 100
507 ms 904 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 2e9;
int n,m,h,w;
pair<int,int> t[2005];
int tr[2005];
bool visited[2005];
bool atinge(pair<int,int> p, int r, int margine)
{
    if(margine==1)
    {
        return (h-p.second)<r;
    }
    else if(margine==2)
    {
        return (w-p.first)<r;
    }
    else if(margine==3)
    {
        return p.second<r;
    }
    else
    {
        return p.first<r;
    }
}
int calc_dist(pair<int,int> x, pair<int,int> y)
{
    return (x.first-y.first)*(x.first-y.first) + (x.second-y.second)*(x.second-y.second);
}
void dfs(int x, int r)
{
    visited[x]=1;
    for(int i=1;i<=n;i++)
        if(!visited[i] && calc_dist(t[x],t[i]) < (tr[x]+tr[i]+2*r)*(tr[x]+tr[i]+2*r))
            dfs(i,r);
}
bool verif(int from, int to, int r)
{
    for(int i=1;i<=n;i++)
        visited[i]=0;
    for(int i=1;i<=n;i++)
        if(!visited[i] && atinge(t[i],2*r+tr[i],from))
            dfs(i,r);
    for(int i=1;i<=n;i++)
        if(visited[i] && atinge(t[i],2*r+tr[i],to))
            return 1;
    return 0;
}
int lim[5][5],rez[5][5];
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m>>w>>h;
    for(int i=1;i<=n;i++)
    {
        cin>>t[i].first>>t[i].second>>tr[i];
    }
    for(int from=1;from<=4;from++)
    {
        for(int to=from+1;to<=4;to++)
        {
            if(verif(from,to,0))
            {
                lim[from][to]=-1;
                continue;
            }
            int st,dr,ans;
            st=0;
            dr=INF;
            ans=0;
            while(st<=dr)
            {
                int mij=(st+dr)/2;
                if(!verif(from,to,mij))
                {
                    ans=mij;
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            lim[from][to] = lim[to][from] = ans;
        }
    }
    rez[1][2] = rez[2][1] = min({lim[1][3],lim[4][3],lim[2][3]});
    rez[1][3] = rez[3][1] = min({lim[3][4],lim[1][3],lim[1][2],lim[2][4]});
    rez[1][4] = rez[4][1] = min({lim[2][4],lim[4][1],lim[4][3]});
    rez[2][3] = rez[3][2] = min({lim[2][4],lim[3][2],lim[1][2]});
    rez[2][4] = rez[4][2] = min({lim[1][3],lim[2][4],lim[1][4],lim[2][3]});
    rez[3][4] = rez[4][3] = min({lim[1][3],lim[4][1],lim[1][2]});
    int qe,qr;
    while(m--)
    {
        cin>>qr>>qe;
        for(int i=1;i<=4;i++)
            if(i==qe || rez[qe][i]>=qr)
                cout<<i;
        cout<<"\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 852 KB Output is correct
2 Correct 507 ms 632 KB Output is correct
3 Correct 393 ms 636 KB Output is correct
4 Correct 479 ms 604 KB Output is correct
5 Correct 440 ms 600 KB Output is correct
6 Correct 330 ms 640 KB Output is correct
7 Correct 300 ms 600 KB Output is correct
8 Correct 249 ms 636 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 860 KB Output is correct
2 Correct 31 ms 604 KB Output is correct
3 Correct 28 ms 604 KB Output is correct
4 Correct 28 ms 604 KB Output is correct
5 Correct 31 ms 604 KB Output is correct
6 Correct 28 ms 860 KB Output is correct
7 Correct 22 ms 724 KB Output is correct
8 Correct 22 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 852 KB Output is correct
2 Correct 507 ms 632 KB Output is correct
3 Correct 393 ms 636 KB Output is correct
4 Correct 479 ms 604 KB Output is correct
5 Correct 440 ms 600 KB Output is correct
6 Correct 330 ms 640 KB Output is correct
7 Correct 300 ms 600 KB Output is correct
8 Correct 249 ms 636 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 33 ms 860 KB Output is correct
12 Correct 31 ms 604 KB Output is correct
13 Correct 28 ms 604 KB Output is correct
14 Correct 28 ms 604 KB Output is correct
15 Correct 31 ms 604 KB Output is correct
16 Correct 28 ms 860 KB Output is correct
17 Correct 22 ms 724 KB Output is correct
18 Correct 22 ms 856 KB Output is correct
19 Correct 416 ms 888 KB Output is correct
20 Correct 392 ms 896 KB Output is correct
21 Correct 406 ms 904 KB Output is correct
22 Correct 442 ms 848 KB Output is correct
23 Correct 433 ms 892 KB Output is correct
24 Correct 302 ms 848 KB Output is correct