답안 #628225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628225 2022-08-13T08:26:44 Z andrei_boaca 섬 항해 (CEOI13_adriatic) C++14
60 / 100
982 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n;
vector<int> muchii[5005];
int my[5005][5];
struct point
{
    int x,y;
} v[5005];
ll dist[5005];
//priority_queue<pii,vector<pii>,greater<pii>> coada;
queue<pii> coada;
vector<int> old[5005],nw[5005];
void bfs(int start)
{
    for(int i=1;i<=n;i++)
        dist[i]=1e9;
    dist[start]=0;
    coada.push({0,start});
    while(!coada.empty())
    {
        int nod=coada.front().second;
        coada.pop();
        for(int i:muchii[nod])
            if(dist[i]>dist[nod]+1)
            {
                dist[i]=dist[nod]+1;
                coada.push({dist[i],i});
            }
    }
}
int sol[5005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i].x>>v[i].y;
    for(int i=1;i<=n;i++)
    {
        int linmin=1e9,linmax=0,colmin=1e9,colmax=0;
        for(int j=1;j<=n;j++)
            if(j!=i)
            {
                if(v[i].x<v[j].x&&v[i].y<v[j].y)
                {
                    nw[i].push_back(j);
                    if(v[j].x<linmin)
                    {
                        linmin=v[j].x;
                        my[i][1]=j;
                    }
                    if(v[j].x>linmax)
                    {
                        linmax=v[j].x;
                        my[i][2]=j;
                    }
                    if(v[j].y<colmin)
                    {
                        colmin=v[j].y;
                        my[i][3]=j;
                    }
                    if(v[j].y>colmax)
                    {
                        colmax=v[j].y;
                        my[i][4]=j;
                    }
                }
                else if(v[i].x>v[j].x&&v[i].y>v[j].y)
                {
                    nw[i].push_back(j);
                    if(v[j].x<linmin)
                    {
                        linmin=v[j].x;
                        my[i][1]=j;
                    }
                    if(v[j].x>linmax)
                    {
                        linmax=v[j].x;
                        my[i][2]=j;
                    }
                    if(v[j].y<colmin)
                    {
                        colmin=v[j].y;
                        my[i][3]=j;
                    }
                    if(v[j].y>colmax)
                    {
                        colmax=v[j].y;
                        my[i][4]=j;
                    }
                }
            }
    }
    /*for(int i=1;i<=4;i++)
        cout<<my[7][i]<<' ';
    cout<<'\n';*/
    for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=4;k++)
            {
                int nod=my[j][k];
                muchii[nod].push_back(j);
                //old[nod].push_back(j);
                //muchii[j].push_back(nod);
            }
        }
    for(int i=1;i<=n;i++)
    {
        sort(muchii[i].begin(),muchii[i].end());
        muchii[i].erase(unique(muchii[i].begin(),muchii[i].end()),muchii[i].end());
        old[i]=muchii[i];
    }
    for(int i=1;i<=n;i++)
    {
        muchii[i].clear();
        muchii[i]=nw[i];
        /*for(int j=1;j<=n;j++)
        {
            if(v[i].x<v[j].x&&v[i].y<v[j].y)
            {
                muchii[i].push_back(j);
                //muchii[j].push_back(i);
            }
            else if(v[i].x>v[j].x&&v[i].y>v[j].y)
            {
                muchii[i].push_back(j);
                //muchii[j].push_back(i);
            }
        }*/
        bfs(i);
        muchii[i].clear();
        muchii[i]=old[i];
        ll suma=0;
        for(int j=1;j<=n;j++)
            suma+=dist[j];
        cout<<suma<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 1784 KB Output is correct
2 Correct 65 ms 11344 KB Output is correct
3 Correct 84 ms 992 KB Output is correct
4 Correct 68 ms 11172 KB Output is correct
5 Correct 67 ms 10120 KB Output is correct
6 Correct 62 ms 1216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 819 ms 8332 KB Output is correct
2 Correct 703 ms 113440 KB Output is correct
3 Correct 917 ms 2460 KB Output is correct
4 Correct 713 ms 112652 KB Output is correct
5 Correct 693 ms 104908 KB Output is correct
6 Correct 723 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 982 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 73 ms 33184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -