#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int DistanceSum(int N, int *X, int *Y) {
if(N <= 2000) {
vector<int> graph[N];
for(int i=0; i<N; i++) {
for(int j=i+1; j<N; j++) {
if(abs(X[i] - X[j]) + abs(Y[i] - Y[j]) == 1) {
graph[i].push_back(j);
graph[j].push_back(i);
}
}
}
int ans = 0;
for(int i=0; i<N; i++) {
queue<int> q;
vector<bool> vis(N);
vector<int> dist(N);
vis[i] = 1; q.push(i);
while(!q.empty()) {
int u = q.front(); q.pop();
for(int &v : graph[u]) {
if(vis[v]) continue;
vis[v] = 1;
dist[v] = dist[u] + 1;
q.push(v);
}
}
for(int j=i+1; j<N; j++) ans += dist[j];
}
return ans;
}
return N;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
440 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
512 KB |
Output is correct |
3 |
Correct |
30 ms |
348 KB |
Output is correct |
4 |
Correct |
33 ms |
348 KB |
Output is correct |
5 |
Correct |
45 ms |
348 KB |
Output is correct |
6 |
Correct |
55 ms |
348 KB |
Output is correct |
7 |
Correct |
56 ms |
348 KB |
Output is correct |
8 |
Correct |
63 ms |
572 KB |
Output is correct |
9 |
Correct |
61 ms |
348 KB |
Output is correct |
10 |
Correct |
61 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |