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;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
const int MAXN = 100100;
int x[MAXN], y[MAXN];
ll d[MAXN];
int n;
vi adj[MAXN];
void bfs (int st) {
FOR(i, 0, n-1) d[i] = -1;
queue<int> q;
q.push(st);
d[st] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : adj[v]) {
if (d[u] == -1) {
d[u] = d[v]+1;
q.push(u);
}
}
}
}
int DistanceSum(int N, int *X, int *Y) {
n = N;
FOR(i, 0, n-1) x[i] = X[i];
FOR(i, 0, n-1) y[i] = Y[i];
FOR(i, 0, n-1) FOR(j, i+1, n-1) {
if (abs(x[i] - x[j]) + abs(y[i] - y[j]) == 1){
adj[i].pb(j);
adj[j].pb(i);
}
}
ll ans = 0;
FOR(i, 0, n-1) {
bfs(i);
FOR(j, 0, n-1) ans += d[j];
}
ans /= 2;
return ans;
}
# | 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... |