#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef pair<int,int> pii;
int xmov[]={0, 1, 0, -1};
int ymov[]={1, 0, -1, 0};
queue<pii> Q;
set<pii> B;
map<pii,int> D;
int ans;
int DistanceSum(int N, int *X, int *Y) {
for(int i=0;i<N;i++)
B.insert({X[i],Y[i]});
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
D[{X[j],Y[j]}]=-1;
D[{X[i],Y[i]}]=0;
Q.push({X[i],Y[i]});
while(!Q.empty()){
pii p=Q.front();
Q.pop();
for(int j=0;j<4;j++)
if(B.count({p.first+xmov[j],p.second+ymov[j]}) and D[{p.first+xmov[j],p.second+ymov[j]}]==-1){
D[{p.first+xmov[j],p.second+ymov[j]}]=D[{p.first,p.second}]+1;
Q.push({p.first+xmov[j],p.second+ymov[j]});
}
}
for(int j=0;j<N;j++)
ans+=D[{X[j],Y[j]}];
}
return ans/2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
360 KB |
Output is correct |
3 |
Correct |
3 ms |
360 KB |
Output is correct |
4 |
Correct |
7 ms |
444 KB |
Output is correct |
5 |
Correct |
9 ms |
448 KB |
Output is correct |
6 |
Correct |
28 ms |
452 KB |
Output is correct |
7 |
Correct |
30 ms |
584 KB |
Output is correct |
8 |
Correct |
29 ms |
584 KB |
Output is correct |
9 |
Correct |
33 ms |
676 KB |
Output is correct |
10 |
Correct |
32 ms |
676 KB |
Output is correct |
11 |
Correct |
36 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1010 ms |
764 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
3076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
3228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |