#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()
#define dist(x) dist[x.first][x.second]
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
int DistanceSum(int N, int *X, int *Y) {
vector<pii> v;
for (int i = 0; i < N; i++) {
v.push_back({X[i], Y[i]});
}
if(N < 5000){
ll res = 0;
vector<pii> off = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
for (auto &i : v)
{
map<int, map<int, int>> dist;
for (auto &j : v) {
dist(j) = INT_MAX;
}
queue<pii> q;
q.push(i);
dist(i) = 0;
while(q.size()){
pii a = q.front(); q.pop();
for (auto &[dx, dy] : off) {
pii b = {a.first + dx, a.second + dy};
if(dist(b) != 0 && dist(b) > dist(a) + 1){
dist(b) = dist(a) + 1;
q.push(b);
}
}
}
for (auto &j : v) {
res += dist(j);
}
}
return res / 2;
}
}
Compilation message
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:14:17: warning: control reaches end of non-void function [-Wreturn-type]
14 | vector<pii> v;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
440 KB |
Output is correct |
6 |
Correct |
22 ms |
348 KB |
Output is correct |
7 |
Correct |
24 ms |
348 KB |
Output is correct |
8 |
Correct |
23 ms |
348 KB |
Output is correct |
9 |
Correct |
21 ms |
600 KB |
Output is correct |
10 |
Correct |
21 ms |
432 KB |
Output is correct |
11 |
Correct |
23 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
751 ms |
540 KB |
Output is correct |
2 |
Correct |
722 ms |
520 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
600 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1336 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1336 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |