이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
#define debug(args...) kout("[ + " string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MOD = 1000000000;
const int MAXN = 100000;
vector <int> path[MAXN+1];
ll BFS(int s, int N) {
vector <int> dis(N, MOD);
dis[s] = 0;
queue <int> nxt;
nxt.push(s);
while (nxt.size()) {
int now = nxt.front();
nxt.pop();
for (int i : path[now]) {
if (dis[i] == MOD) {
dis[i] = dis[now] + 1;
nxt.push(i);
}
}
}
ll sum = 0;
for (int i = s+1; i < N; i++)
sum += dis[i];
return sum;
}
void init(int N) {
for (int i = 0; i < N; i++)
path[i].clear();
}
int DistanceSum(int N, int *X, int *Y) {
init(N);
ll ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j) continue;
if (abs(X[i]-X[j])+abs(Y[i]-Y[j]) <= 1) {
path[i].pb(j);
path[j].pb(i);
}
}
}
for (int i = 0; i < N; i++)
ans = (ans + BFS(i, N)) % MOD;
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... |