#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9;
int x[] = {1,-1,0,0};
int y[] = {0,0,1,-1};
int D[2010][2010], M[2010][2010];
queue<pair<int,int>> Q;
int DtanceSum(int N, int *X, int *Y) {
ll A = 0, T = 0;
if(N<=2000){
int xx = *min_element(X,X+N), xd = *min_element(Y,Y+N);
for(int i = 0; i < N; i++)
X[i]-=xx,Y[i]-=xd, M[X[i]][Y[i]]=i+1;
for(int i = 0; i < N; i++){
Q.push({X[i],Y[i]}); T = 0;
for(int j = 0; j < N; j++)
D[X[j]][Y[j]]=(j!=i)*-1;
while(!empty(Q)){
auto [x1,y1] = Q.front(); Q.pop();
T+=D[x1][y1]*(M[x1][y1]>i); T%=MOD;
for(int k = 0; k < 4; k++){
int x2 = x1+x[k], y2 = y1+y[k];
if(x2<0 or y2<0 or D[x2][y2]!=-1) continue;
D[x2][y2] = D[x1][y1]+1, Q.push({x2,y2});
}
}
A+=T, A%=MOD;
}
return A;
}
for(int j : {0,1}){
T = 0; sort(X,X+N);
for(ll i = 0; i < N; i++){
A+=(1ll*X[i]*i-T+MOD)%MOD;
T+=X[i], T%=MOD; A%=MOD;swap(X[i],Y[i]);
}
}
return (int)A;
}
Compilation message
city.cpp: In function 'int DtanceSum(int, int*, int*)':
city.cpp:33:13: warning: unused variable 'j' [-Wunused-variable]
33 | for(int j : {0,1}){
| ^
/usr/bin/ld: /tmp/ccILyXIW.o: in function `main':
grader.cpp:(.text.startup+0x104): undefined reference to `DistanceSum(int, int*, int*)'
collect2: error: ld returned 1 exit status