#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e3 + 20;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int dist[maxN][maxN];
int DistanceSum(int N, int *X, int *Y) {
fill_n(&dist[0][0], maxN * maxN, -1);
int min_X = X[0];
for (int i = 0; i < N; i++) {
min_X = min(min_X, X[i]);
}
for (int i = 0; i < N; i++) {
X[i] -= min_X - 1;
}
int min_Y = Y[0];
for (int i = 0; i < N; i++) {
min_Y = min(min_Y, Y[i]);
}
for (int i = 0; i < N; i++) {
Y[i] -= min_Y - 1;
}
int res = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[X[j]][Y[j]] = 0;
}
dist[X[i]][Y[i]] = 1;
deque<pair<int, int>> Q;
Q.emplace_back(X[i], Y[i]);
while (!Q.empty()) {
int cx = Q.front().first;
int cy = Q.front().second;
Q.pop_front();
int cur = dist[cx][cy];
res += cur - 1;
for (int d = 0; d < 4; d++) {
int nx = cx + dx[d];
int ny = cy + dy[d];
if (dist[nx][ny] == 0) {
dist[nx][ny] = cur + 1;
Q.emplace_back(nx, ny);
}
}
}
}
return res / 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16212 KB |
Output is correct |
2 |
Correct |
6 ms |
16212 KB |
Output is correct |
3 |
Correct |
6 ms |
16212 KB |
Output is correct |
4 |
Correct |
6 ms |
16212 KB |
Output is correct |
5 |
Correct |
6 ms |
16212 KB |
Output is correct |
6 |
Correct |
7 ms |
16212 KB |
Output is correct |
7 |
Correct |
6 ms |
16212 KB |
Output is correct |
8 |
Correct |
6 ms |
16212 KB |
Output is correct |
9 |
Correct |
7 ms |
16212 KB |
Output is correct |
10 |
Correct |
6 ms |
16168 KB |
Output is correct |
11 |
Correct |
6 ms |
16212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
16280 KB |
Output is correct |
2 |
Correct |
22 ms |
16208 KB |
Output is correct |
3 |
Correct |
48 ms |
16236 KB |
Output is correct |
4 |
Correct |
45 ms |
16212 KB |
Output is correct |
5 |
Correct |
80 ms |
16284 KB |
Output is correct |
6 |
Correct |
72 ms |
16296 KB |
Output is correct |
7 |
Correct |
87 ms |
16212 KB |
Output is correct |
8 |
Correct |
69 ms |
16288 KB |
Output is correct |
9 |
Correct |
66 ms |
16288 KB |
Output is correct |
10 |
Correct |
66 ms |
16292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
16468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1076 ms |
16468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |