#include <bits/stdc++.h>
using namespace std;
vector<int> G[2009]; int dist[2009], mod = 1000000000;
long long cx[200009], cy[200009];
int DistanceSum(int N, int *X, int *Y) {
if (N > 2000) {
int minx = 2147483647, miny = 2147483647;
for (int i = 0; i < N; i++) { minx = min(minx, X[i]); miny = min(miny, Y[i]); }
for (int i = 0; i < N; i++) { cx[X[i] - minx]++; cy[Y[i] - miny]++; }
long long sum = 0;
for (int i = 0; i <= N; i++) sum += 1LL * cx[i] * (1LL * N - cx[i]);
for (int i = 0; i <= N; i++) sum += 1LL * cy[i] * (1LL * N - cy[i]);
sum /= 2LL;
return sum % mod;
}
else {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
int V = abs(X[i] - X[j]) + abs(Y[i] - Y[j]);
if (V == 1) G[i].push_back(j);
}
}
int sum = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) dist[j] = 10000;
queue<int> que; que.push(i); dist[i] = 0;
while (!que.empty()) {
int pos = que.front(); que.pop();
for (int j = 0; j < (int)G[pos].size(); j++) {
if (dist[G[pos][j]] > dist[pos] + 1) {
dist[G[pos][j]] = dist[pos] + 1;
que.push(G[pos][j]);
}
}
}
for (int j = i + 1; j < N; j++) { sum += dist[j]; sum %= mod; }
}
return sum;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
384 KB |
Output is correct |
2 |
Correct |
34 ms |
384 KB |
Output is correct |
3 |
Correct |
75 ms |
384 KB |
Output is correct |
4 |
Correct |
98 ms |
384 KB |
Output is correct |
5 |
Correct |
155 ms |
504 KB |
Output is correct |
6 |
Correct |
183 ms |
632 KB |
Output is correct |
7 |
Correct |
148 ms |
508 KB |
Output is correct |
8 |
Correct |
151 ms |
632 KB |
Output is correct |
9 |
Correct |
156 ms |
552 KB |
Output is correct |
10 |
Correct |
151 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |