Submission #628198

# Submission time Handle Problem Language Result Execution time Memory
628198 2022-08-13T07:51:14 Z andrei_boaca Adriatic (CEOI13_adriatic) C++14
50 / 100
2000 ms 12560 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n;
vector<int> muchii[250005];
int my[250005][5];
struct point
{
    int x,y;
} v[250005];
ll dist[250005];
priority_queue<pii,vector<pii>,greater<pii>> coada;
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.top().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[250005];
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)
            {
                bool ok=0;
                if(i==7)
                    ok=1;
                if(v[i].x<v[j].x&&v[i].y<v[j].y)
                {
                    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)
                {
                    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 i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            muchii[j].clear();
        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);
            }
        }
        for(int j=1;j<=n;j++)
            if(j!=i)
            {
                for(int k=1;k<=4;k++)
                {
                    int nod=my[j][k];
                    muchii[nod].push_back(j);
                    muchii[j].push_back(nod);
                }
            }
        bfs(i);
        ll suma=0;
        for(int j=1;j<=n;j++)
            suma+=dist[j];
        cout<<suma<<'\n';
    }
    return 0;
}

Compilation message

adriatic.cpp: In function 'int main()':
adriatic.cpp:47:22: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   47 |                 bool ok=0;
      |                      ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6228 KB Output is correct
2 Correct 5 ms 6228 KB Output is correct
3 Correct 4 ms 6228 KB Output is correct
4 Correct 5 ms 6264 KB Output is correct
5 Correct 4 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 6932 KB Output is correct
2 Correct 326 ms 12560 KB Output is correct
3 Correct 319 ms 6544 KB Output is correct
4 Correct 327 ms 12456 KB Output is correct
5 Correct 326 ms 11848 KB Output is correct
6 Correct 259 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 8924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2058 ms 7020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2057 ms 10492 KB Time limit exceeded
2 Halted 0 ms 0 KB -