#include<bits/stdc++.h>
//#include"grader.cpp"
using namespace std;
typedef long long ll;
vector<int>g[2005];
int d[2005][2005];
int DistanceSum(int N,int *X,int *Y){
if(N<2001){
int n=N;
int i,j,res=0;
for(i=0;i+1<n;i++)
for(j=i+1;j<n;j++){d[i][j]=INT_MAX,d[j][i]=INT_MAX;if(abs(X[i]-X[j])+abs(Y[i]-Y[j])==1){
g[i].push_back(j);
g[j].push_back(i);
}}
for(i=0;i<n;i++){
queue<int>q;
q.push(i);
while(!q.empty()){
int v=q.front();
q.pop();
for(int to:g[v])if(d[i][to]>d[i][v]+1){
d[i][to]=d[i][v]+1;
q.push(to);
}
}
}
for(i=0;i+1<n;i++)
for(j=i+1;j<n;j++)res=(res+d[i][j])%(1000000000);
return res;
}
ll res=0,sum_x=0,sum_y=0,cur_x=0,cur_y=0,n=N,i;
sort(X,X+n);
sort(Y,Y+n);
for(i=0;i<n;i++)sum_x+=1ll*X[i],sum_y+=1ll*Y[i];
for(i=0;i<n;i++){
cur_x+=1ll*X[i],cur_y+=1ll*Y[i];
res=(res+sum_x-cur_x-(1ll*X[i])*(n+1-i))%(1000000000);
res=(res+sum_y-cur_y-(1ll*Y[i])*(n+1-i))%(1000000000);
}
return res;
}
/*
11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
1280 KB |
Output is correct |
7 |
Correct |
2 ms |
1280 KB |
Output is correct |
8 |
Correct |
2 ms |
1280 KB |
Output is correct |
9 |
Correct |
2 ms |
1280 KB |
Output is correct |
10 |
Correct |
2 ms |
1280 KB |
Output is correct |
11 |
Correct |
2 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
8192 KB |
Output is correct |
2 |
Correct |
40 ms |
8192 KB |
Output is correct |
3 |
Correct |
88 ms |
12160 KB |
Output is correct |
4 |
Correct |
94 ms |
12160 KB |
Output is correct |
5 |
Correct |
157 ms |
16120 KB |
Output is correct |
6 |
Correct |
170 ms |
16204 KB |
Output is correct |
7 |
Correct |
163 ms |
16120 KB |
Output is correct |
8 |
Correct |
169 ms |
16128 KB |
Output is correct |
9 |
Correct |
171 ms |
16212 KB |
Output is correct |
10 |
Correct |
165 ms |
16124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |