#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
int n;
map<pair<int,int>,int> aa;
vector<int> xx={0,1,0,-1};
vector<int> yy={1,0,-1,0};
int DistanceSum(int nn, int x[], int y[]) {
n=nn;
for(int i=0;i<n;i++){
aa[{x[i],y[i]}]=1;
}
llo ans=0;
for(int i=0;i<n;i++){
map<pair<int,int>,int> dist;
dist[{x[i],y[i]}]=0;
priority_queue<pair<int,pair<int,int>>> ac;
ac.push({0,{x[i],y[i]}});
while(ac.size()){
pair<int,pair<int,int>> tt=ac.top();
ac.pop();
tt.a*=(-1);
// cout<<tt.a<<","<<tt.b.a<<","<<tt.b.b<<endl;
for(int j=0;j<4;j++){
if(aa.find({tt.b.a+xx[j],tt.b.b+yy[j]})==aa.end()){
continue;
}
if(dist.find({tt.b.a+xx[j],tt.b.b+yy[j]})!=dist.end()){
if(dist[{tt.b.a+xx[j],tt.b.b+yy[j]}]>tt.a+1){
dist[{tt.b.a+xx[j],tt.b.b+yy[j]}]=tt.a+1;
ac.push({-tt.a-1,{tt.b.a+xx[j],tt.b.b+yy[j]}});
}
}
else{
dist[{tt.b.a+xx[j],tt.b.b+yy[j]}]=tt.a+1;
ac.push({-tt.a-1,{tt.b.a+xx[j],tt.b.b+yy[j]}});
}
}
}
for(int j=0;j<n;j++){
ans+=dist[{x[j],y[j]}];
}
// cout<<i<<endl;
}
ans/=2;
ans%=((llo)1e9);
int ans2=ans;
return ans2;
return 0;
}
/*
11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6
*/
/*
g++ -DEVAL -Wall -static -O2 -o aa grader.cpp city.cpp
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
11 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
384 KB |
Output is correct |
6 |
Correct |
36 ms |
384 KB |
Output is correct |
7 |
Correct |
38 ms |
384 KB |
Output is correct |
8 |
Correct |
33 ms |
384 KB |
Output is correct |
9 |
Correct |
38 ms |
384 KB |
Output is correct |
10 |
Correct |
39 ms |
384 KB |
Output is correct |
11 |
Correct |
40 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
988 ms |
632 KB |
Output is correct |
2 |
Correct |
995 ms |
632 KB |
Output is correct |
3 |
Execution timed out |
1099 ms |
512 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
3468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
3192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |