#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1'000'000'000;
vector<pair<int, int>> dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int DistanceSum(int N, int *X, int *Y) {
// cerr << "!!! BRUTE SOLUTION " << endl;
map<pair<int, int>, int> cell_index;
for (int i = 0; i < N; ++i) cell_index[{X[i], Y[i]}] = i;
vector<vector<int>> graph(N);
for (int i = 0; i < N; ++i) {
for (auto [dx, dy] : dirs) {
int nx = X[i] + dx, ny = Y[i] + dy;
auto possible_index = cell_index.find({nx, ny});
if (possible_index != cell_index.end()) {
graph[i].push_back(possible_index->second);
}
}
}
ll ans = 0;
for (int i = 0; i < N; ++i) {
vector<int> dist(N, -1);
dist[i] = 0;
queue<int> q;
q.push(i);
while (!q.empty()) {
int cur = q.front(); q.pop();
for (int nxt : graph[cur]) {
if (dist[nxt] != -1) continue;
dist[nxt] = dist[cur] + 1;
q.push(nxt);
}
}
ans += accumulate(dist.begin(), dist.end(), 0LL);
}
return ans / 2 % MOD;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
348 KB |
Output is correct |
3 |
Correct |
35 ms |
600 KB |
Output is correct |
4 |
Correct |
33 ms |
604 KB |
Output is correct |
5 |
Correct |
51 ms |
604 KB |
Output is correct |
6 |
Correct |
60 ms |
600 KB |
Output is correct |
7 |
Correct |
61 ms |
604 KB |
Output is correct |
8 |
Correct |
60 ms |
696 KB |
Output is correct |
9 |
Correct |
53 ms |
604 KB |
Output is correct |
10 |
Correct |
39 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1027 ms |
2904 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
2908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |