#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
int xmov[]={0, 1, 0, -1};
int ymov[]={1, 0, -1, 0};
int K;
queue<pii> Q;
int B[2005][2005];
int D[2005][2005];
int ans;
int DistanceSum(int N, int *X, int *Y) {
K=*min_element(X,X+N);
for(int i=0;i<N;i++)
X[i]-=K;
K=*min_element(Y,Y+N);
for(int i=0;i<N;i++)
Y[i]-=K;
for(int i=0;i<N;i++)
B[X[i]][Y[i]]=true;
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[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
672 KB |
Output is correct |
7 |
Correct |
3 ms |
672 KB |
Output is correct |
8 |
Correct |
4 ms |
672 KB |
Output is correct |
9 |
Correct |
5 ms |
800 KB |
Output is correct |
10 |
Correct |
5 ms |
800 KB |
Output is correct |
11 |
Correct |
4 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
948 KB |
Output is correct |
2 |
Correct |
37 ms |
1076 KB |
Output is correct |
3 |
Correct |
123 ms |
1260 KB |
Output is correct |
4 |
Correct |
90 ms |
1260 KB |
Output is correct |
5 |
Correct |
206 ms |
1476 KB |
Output is correct |
6 |
Correct |
164 ms |
1476 KB |
Output is correct |
7 |
Correct |
223 ms |
1960 KB |
Output is correct |
8 |
Correct |
159 ms |
1960 KB |
Output is correct |
9 |
Correct |
160 ms |
1960 KB |
Output is correct |
10 |
Correct |
121 ms |
1960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1068 ms |
3420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1081 ms |
3932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |