#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int DistanceSum(int N, int *X, int *Y) {
int res = 0;
for (int i = 0; i < N; i++) {
map<pair<int, int>, int> dist;
for (int j = 0; j < N; j++) {
if (j != i) {
dist[make_pair(X[j], Y[j])] = 0;
}
}
dist[make_pair(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[make_pair(cx, cy)];
res += cur - 1;
for (int d = 0; d < 4; d++) {
int nx = cx + dx[d];
int ny = cy + dy[d];
auto it = dist.find(make_pair(nx, ny));
if (it != dist.end() && it->second == 0) {
dist[make_pair(nx, ny)] = cur + 1;
Q.emplace_back(nx, ny);
}
}
}
}
return res / 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
308 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
11 ms |
216 KB |
Output is correct |
7 |
Correct |
12 ms |
324 KB |
Output is correct |
8 |
Correct |
12 ms |
320 KB |
Output is correct |
9 |
Correct |
13 ms |
320 KB |
Output is correct |
10 |
Correct |
13 ms |
308 KB |
Output is correct |
11 |
Correct |
13 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
453 ms |
364 KB |
Output is correct |
2 |
Correct |
428 ms |
360 KB |
Output is correct |
3 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1058 ms |
1876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1083 ms |
1876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |