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>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)
using namespace std;
const int MOD = 1000000000;
int DistanceSum(int n, int x[], int y[]) {
vector<tuple<int,int,int>> p(n);
vector<vector<int>> g(n);
for(int i = 0; i < n; i++) p[i] = {i, x[i], y[i]};
sort(all(p), [](auto a, auto b){return get<1>(a) != get<1>(b) ? get<1>(a) < get<1>(b) : get<2>(a) < get<2>(b);});
for(int i = 1; i < n; i++) if(get<1>(p[i]) == get<1>(p[i-1]) && get<2>(p[i]) == get<2>(p[i-1])+1) {
int a = get<0>(p[i]), b = get<0>(p[i-1]);
g[a].pb(b), g[b].pb(a);
}
sort(all(p), [](auto a, auto b){return get<2>(a) != get<2>(b) ? get<2>(a) < get<2>(b) : get<1>(a) < get<1>(b);});
for(int i = 1; i < n; i++) if(get<2>(p[i]) == get<2>(p[i-1]) && get<1>(p[i]) == get<1>(p[i-1])+1) {
int a = get<0>(p[i]), b = get<0>(p[i-1]);
g[a].pb(b), g[b].pb(a);
}
int ans = 0;
for(int i = 0; i < n; i++) {
queue<int> q;
vector<int> dis(n, -1);
dis[i] = 0;
q.push(i);
while(!q.empty()) {
int i = q.front(); q.pop();
for(int j: g[i]) if(dis[j] == -1) dis[j] = dis[i] + 1, q.push(j);
}
for(int j = 0; j < i; j++) ans = (ans + dis[j]) % MOD;
}
debug(ans);
return ans;
}
# | 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... |