#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n;
vector<int> muchii[25005];
int my[25005][5];
struct point
{
int x,y;
} v[25005];
ll dist[25005];
//priority_queue<pii,vector<pii>,greater<pii>> coada;
queue<pii> coada;
vector<int> old[25005];
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[25005];
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)
{
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 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
2144 KB |
Output is correct |
2 |
Correct |
74 ms |
7808 KB |
Output is correct |
3 |
Correct |
79 ms |
1732 KB |
Output is correct |
4 |
Correct |
76 ms |
7720 KB |
Output is correct |
5 |
Correct |
73 ms |
7064 KB |
Output is correct |
6 |
Correct |
68 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
977 ms |
5988 KB |
Output is correct |
2 |
Correct |
809 ms |
66316 KB |
Output is correct |
3 |
Correct |
1004 ms |
2676 KB |
Output is correct |
4 |
Correct |
819 ms |
65800 KB |
Output is correct |
5 |
Correct |
809 ms |
61220 KB |
Output is correct |
6 |
Correct |
811 ms |
2112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2091 ms |
2208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
25 ms |
4180 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |