This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |