#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;
vector<int> old[250005];
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 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++)
{
muchii[i].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);
}
}
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;
}
Compilation message
adriatic.cpp: In function 'int main()':
adriatic.cpp:48:22: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
48 | bool ok=0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12092 KB |
Output is correct |
2 |
Correct |
9 ms |
12012 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Correct |
8 ms |
12116 KB |
Output is correct |
5 |
Correct |
8 ms |
12084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
12804 KB |
Output is correct |
2 |
Correct |
215 ms |
18356 KB |
Output is correct |
3 |
Correct |
189 ms |
12364 KB |
Output is correct |
4 |
Correct |
211 ms |
18268 KB |
Output is correct |
5 |
Correct |
191 ms |
17720 KB |
Output is correct |
6 |
Correct |
126 ms |
12416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2090 ms |
16444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2086 ms |
12628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2062 ms |
14056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |