#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
int n;
map<pair<int,int>,int> aa;
vector<int> xx={0,1,0,-1};
vector<int> yy={1,0,-1,0};
vector<int> adj[2001];
int dist[2001];
int DistanceSum(int nn, int x[], int y[]) {
n=nn;
for(int i=0;i<n;i++){
aa[{x[i],y[i]}]=i;
}
if(nn<=2000){
pair<int,pair<int,int>> tt;
for(int i=0;i<n;i++){
for(int j=0;j<4;j++){
if(aa.find({x[i]+xx[j],y[i]+yy[j]})==aa.end()){
continue;
}
adj[i].pb(aa[{x[i]+xx[j],y[i]+yy[j]}]);
}
}
llo ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
dist[j]=-1;
}
dist[i]=0;
priority_queue<pair<int,int>> ac;
ac.push({0,i});
while(ac.size()){
pair<int,int> tt=ac.top();
ac.pop();
tt.a*=(-1);
// cout<<tt.a<<","<<tt.b.a<<","<<tt.b.b<<endl;
for(auto j:adj[tt.b]){
if(dist[j]>tt.a+1 or dist[j]==-1){
dist[j]=tt.a+1;
ac.push({-tt.a-1,j});
}
}
}
for(int j=0;j<n;j++){
ans+=dist[j];
}
// cout<<i<<endl;
}
ans/=2;
ans%=((llo)1e9);
int ans2=ans;
return ans2;
}
vector<int> kk;
vector<int> ll;
for(int i=0;i<n;i++){
kk.pb(x[i]);
ll.pb(y[i]);
}
sort(kk.begin(),kk.end());
sort(ll.begin(),ll.end());
int su=0;
llo ans=0;
for(int i=n-1;i>=0;i--){
// cout<<kk[i]<<","<<su<<endl;
ans+=su-(n-i-1)*kk[i];
su+=kk[i];
}
su=0;
for(int i=n-1;i>=0;i--){
// cout<<ll[i]<<','<<su<<endl;
ans+=su-(n-i-1)*ll[i];
su+=ll[i];
}
ans%=((llo)1e9);
return (int)ans;
return 0;
}
/*
11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6
*/
/*
g++ -DEVAL -Wall -static -O2 -o aa grader.cpp city.cpp
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
8 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
512 KB |
Output is correct |
2 |
Correct |
84 ms |
512 KB |
Output is correct |
3 |
Correct |
288 ms |
512 KB |
Output is correct |
4 |
Correct |
191 ms |
512 KB |
Output is correct |
5 |
Correct |
374 ms |
632 KB |
Output is correct |
6 |
Correct |
328 ms |
640 KB |
Output is correct |
7 |
Correct |
312 ms |
632 KB |
Output is correct |
8 |
Correct |
322 ms |
760 KB |
Output is correct |
9 |
Correct |
390 ms |
632 KB |
Output is correct |
10 |
Correct |
378 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2176 KB |
Output is correct |
2 |
Correct |
17 ms |
2304 KB |
Output is correct |
3 |
Correct |
38 ms |
4988 KB |
Output is correct |
4 |
Correct |
45 ms |
4860 KB |
Output is correct |
5 |
Correct |
83 ms |
9124 KB |
Output is correct |
6 |
Correct |
82 ms |
9124 KB |
Output is correct |
7 |
Correct |
92 ms |
9252 KB |
Output is correct |
8 |
Correct |
82 ms |
9124 KB |
Output is correct |
9 |
Correct |
91 ms |
9124 KB |
Output is correct |
10 |
Correct |
97 ms |
9124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
2176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |