#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;
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];
ll ans;
ll S;
ll mod=1e9;
int DistanceSum(int N, int *X, int *Y) {
if(false and N<=2000){
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;
}
sort(X,X+N);
for(ll i=0;i<N;i++){
ans=(ans+i*X[i]-S)%mod;
S=(S+X[i])%mod;
}
S=0;
sort(Y,Y+N);
for(ll i=0;i<N;i++){
ans=(ans+i*Y[i]-S)%mod;
S=(S+Y[i])%mod;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
672 KB |
Output is correct |
2 |
Correct |
10 ms |
748 KB |
Output is correct |
3 |
Correct |
21 ms |
1552 KB |
Output is correct |
4 |
Correct |
21 ms |
1912 KB |
Output is correct |
5 |
Correct |
46 ms |
3084 KB |
Output is correct |
6 |
Correct |
39 ms |
3872 KB |
Output is correct |
7 |
Correct |
55 ms |
4704 KB |
Output is correct |
8 |
Correct |
48 ms |
5596 KB |
Output is correct |
9 |
Correct |
41 ms |
6244 KB |
Output is correct |
10 |
Correct |
47 ms |
6964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
6964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |