This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |