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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()
#define dist(x) dist[x.first][x.second]
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
int DistanceSum(int N, int *X, int *Y) {
vector<pii> v;
for (int i = 0; i < N; i++) {
v.push_back({X[i], Y[i]});
}
if(N < 5000){
ll res = 0;
vector<pii> off = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
for (auto &i : v)
{
map<int, map<int, int>> dist;
for (auto &j : v) {
dist(j) = INT_MAX;
}
queue<pii> q;
q.push(i);
dist(i) = 0;
while(q.size()){
pii a = q.front(); q.pop();
for (auto &[dx, dy] : off) {
pii b = {a.first + dx, a.second + dy};
if(dist(b) != 0 && dist(b) > dist(a) + 1){
dist(b) = dist(a) + 1;
q.push(b);
}
}
}
for (auto &j : v) {
res += dist(j);
}
}
return res / 2;
}
}
Compilation message (stderr)
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:14:17: warning: control reaches end of non-void function [-Wreturn-type]
14 | vector<pii> v;
| ^
# | 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... |