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 <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
for (IT it=bg;it!=ed;it++) {
if (it == bg) os << "{" << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif
const int MAXN = 20003;
map<pii, int> id;
vector<int> edge[MAXN];
int DistanceSum(int n, int *x, int *y) {
for (int i=0; i<n; i++) {
id[pii(x[i], y[i])] = i;
}
for (int i=0; i<n; i++) {
vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
for (int j=0; j<4; j++) {
int nx = x[i] + dx[j];
int ny = y[i] + dy[j];
if (id.count(pii(nx, ny))) {
int z = id[pii(nx,ny)];
edge[i].emplace_back(z);
edge[z].emplace_back(i);
}
}
}
int ans = 0;
for (int i=0; i<n; i++) {
vector<int> dis(n, -1);
dis[i] = 0;
queue<int> bfs;
bfs.emplace(i);
while (bfs.size()) {
int cur = bfs.front();
bfs.pop();
for (int z : edge[cur]) {
if (dis[z] == -1) {
dis[z] = dis[cur] + 1;
bfs.emplace(z);
ans += dis[z];
}
}
}
}
return ans / 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... |