#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010, inf = 1e9;
int N;
vector<int> edge[MAX_N];
ll bfs_all(int s) {
vector<int> dis(N, inf); dis[s] = 0;
queue<int> q; q.push(s);
ll res = 0;
while (q.size()) {
int x = q.front(); q.pop();
res += dis[x];
for (int u : edge[x]) if (chmin(dis[u], dis[x] + 1))
q.push(u);
}
return res;
}
ll cal(int N, int *X, int *Y) {
ll res = 0;
map<int, int> cnt;
for (int i = 0;i < N;++i) ++cnt[X[i]];
ll L = 0, R = N;
for (auto [_, c] : cnt) {
L += c, R -= c;
res += L * R;
}
return res * 2;
}
int DistanceSum(int N, int *X, int *Y) {
::N = N;
ll res = 0;
if (N > 2000) {
res = cal(N, X, Y) + cal(N, Y, X);
}
else {
for (int i = 0;i < N;++i)
for (int j = 0;j < N;++j) if (i != j)
if (abs(X[i]-X[j]) + abs(Y[i]-Y[j]) == 1)
edge[i].pb(j);
for (int i = 0;i < N;++i)
res += bfs_all(i);
}
return res / 2 % 1'000'000'000;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
7 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
6 ms |
7404 KB |
Output is correct |
9 |
Correct |
7 ms |
7404 KB |
Output is correct |
10 |
Correct |
6 ms |
7404 KB |
Output is correct |
11 |
Correct |
6 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
7404 KB |
Output is correct |
2 |
Correct |
39 ms |
7404 KB |
Output is correct |
3 |
Correct |
78 ms |
7532 KB |
Output is correct |
4 |
Correct |
86 ms |
7552 KB |
Output is correct |
5 |
Correct |
135 ms |
7404 KB |
Output is correct |
6 |
Correct |
147 ms |
7404 KB |
Output is correct |
7 |
Correct |
144 ms |
7404 KB |
Output is correct |
8 |
Correct |
150 ms |
7520 KB |
Output is correct |
9 |
Correct |
147 ms |
7532 KB |
Output is correct |
10 |
Correct |
145 ms |
7532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7532 KB |
Output is correct |
2 |
Correct |
11 ms |
7660 KB |
Output is correct |
3 |
Correct |
21 ms |
7892 KB |
Output is correct |
4 |
Correct |
24 ms |
7916 KB |
Output is correct |
5 |
Correct |
39 ms |
8172 KB |
Output is correct |
6 |
Correct |
40 ms |
8428 KB |
Output is correct |
7 |
Correct |
41 ms |
8428 KB |
Output is correct |
8 |
Correct |
37 ms |
8172 KB |
Output is correct |
9 |
Correct |
38 ms |
8300 KB |
Output is correct |
10 |
Correct |
45 ms |
9708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
7660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |