#include<bits/stdc++.h>
using namespace std;
int mp[2005][2005], vis[2005][2005], dis[2005][2005];
queue< pair<int,int> > q;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
vector<int> XX, YY;
int DistanceSum(int N, int *X, int *Y) {
for(int i=0; i<N; i++) {
XX.push_back(X[i]);
YY.push_back(Y[i]);
}
sort(XX.begin(), XX.end()); sort(YY.begin(), YY.end());
if(N <= 2000) {
for(int i=0; i<N; i++) {
X[i] -= XX[0];
Y[i] -= YY[0];
}
for(int i=0; i<N; i++) {
mp[X[i]][Y[i]] = 1;
}
long long ans = 0;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) vis[X[j]][Y[j]] = 0;
vis[X[i]][Y[i]] = 1;
q.push({X[i], Y[i]});
dis[X[i]][Y[i]] = 0;
while(!q.empty()) {
int x = q.front().first;
int y = q.front().second;
ans += dis[x][y];
q.pop();
for(int j=0; j<4; j++) {
if(mp[x+dx[j]][y+dy[j]] == 1 && vis[x+dx[j]][y+dy[j]] == 0) {
vis[x+dx[j]][y+dy[j]] = 1;
dis[x+dx[j]][y+dy[j]] = dis[x][y] + 1;
q.push({x+dx[j], y+dy[j]});
}
}
}
}
return (ans/2) % 1000000000;
} else {
long long tmp = 0, ans = 0;
for(int i=0; i<N; i++) {
ans += XX[i] * i - tmp;
ans %= 1000000000;
tmp += XX[i];
}
tmp = 0;
for(int i=0; i<N; i++) {
ans += YY[i] * i - tmp;
ans %= 1000000000;
tmp += YY[i];
}
return ans % 1000000000;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
980 KB |
Output is correct |
2 |
Correct |
33 ms |
852 KB |
Output is correct |
3 |
Correct |
88 ms |
1312 KB |
Output is correct |
4 |
Correct |
75 ms |
1252 KB |
Output is correct |
5 |
Correct |
149 ms |
1540 KB |
Output is correct |
6 |
Correct |
119 ms |
1444 KB |
Output is correct |
7 |
Correct |
153 ms |
2056 KB |
Output is correct |
8 |
Correct |
111 ms |
2028 KB |
Output is correct |
9 |
Correct |
114 ms |
1180 KB |
Output is correct |
10 |
Correct |
92 ms |
1140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
724 KB |
Output is correct |
2 |
Correct |
6 ms |
724 KB |
Output is correct |
3 |
Correct |
14 ms |
1360 KB |
Output is correct |
4 |
Correct |
12 ms |
1360 KB |
Output is correct |
5 |
Correct |
25 ms |
2128 KB |
Output is correct |
6 |
Correct |
26 ms |
2068 KB |
Output is correct |
7 |
Correct |
32 ms |
2132 KB |
Output is correct |
8 |
Correct |
30 ms |
2104 KB |
Output is correct |
9 |
Correct |
27 ms |
2152 KB |
Output is correct |
10 |
Incorrect |
24 ms |
2128 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |