#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 |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
384 KB |
Output is correct |
2 |
Correct |
27 ms |
384 KB |
Output is correct |
3 |
Correct |
63 ms |
504 KB |
Output is correct |
4 |
Correct |
62 ms |
512 KB |
Output is correct |
5 |
Correct |
116 ms |
512 KB |
Output is correct |
6 |
Correct |
105 ms |
632 KB |
Output is correct |
7 |
Correct |
119 ms |
512 KB |
Output is correct |
8 |
Correct |
106 ms |
512 KB |
Output is correct |
9 |
Correct |
106 ms |
512 KB |
Output is correct |
10 |
Correct |
104 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
2048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
2048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |