#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
#define debug(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 pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MOD = 1000000000;
const int MAXN = 100000;
vector <int> path[MAXN+1];
ll BFS(int s, int N) {
vector <int> dis(N, MOD);
dis[s] = 0;
queue <int> nxt;
nxt.push(s);
while (nxt.size()) {
int now = nxt.front();
nxt.pop();
for (int i : path[now]) {
if (dis[i] == MOD) {
dis[i] = dis[now] + 1;
nxt.push(i);
}
}
}
ll sum = 0;
for (int i = s+1; i < N; i++)
sum += dis[i];
return sum;
}
void init(int N) {
for (int i = 0; i < N; i++)
path[i].clear();
}
int DistanceSum(int N, int *X, int *Y) {
init(N);
ll ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j) continue;
if (abs(X[i]-X[j])+abs(Y[i]-Y[j]) <= 1) {
path[i].pb(j);
path[j].pb(i);
}
}
}
for (int i = 0; i < N; i++)
ans = (ans + BFS(i, N)) % MOD;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
3 ms |
2668 KB |
Output is correct |
7 |
Correct |
3 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2668 KB |
Output is correct |
9 |
Correct |
3 ms |
2668 KB |
Output is correct |
10 |
Correct |
3 ms |
2668 KB |
Output is correct |
11 |
Correct |
4 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
2796 KB |
Output is correct |
2 |
Correct |
40 ms |
2796 KB |
Output is correct |
3 |
Correct |
87 ms |
2796 KB |
Output is correct |
4 |
Correct |
89 ms |
2796 KB |
Output is correct |
5 |
Correct |
159 ms |
2924 KB |
Output is correct |
6 |
Correct |
161 ms |
2924 KB |
Output is correct |
7 |
Correct |
155 ms |
2796 KB |
Output is correct |
8 |
Correct |
160 ms |
2816 KB |
Output is correct |
9 |
Correct |
159 ms |
2924 KB |
Output is correct |
10 |
Correct |
157 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
4076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
3612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |