#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
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 INF = 1e18;
const int MAXN = 100000;
vector <int> path[MAXN];
vector <int> deg;
vector <bool> vis;
map <pii,int> appr;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int BFS(int s, int N) {
vector <int> dis(N, INF);
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] == INF) {
dis[i] = dis[now] + 1;
nxt.push(i);
}
}
}
int 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();
appr.clear();
deg.resize(N);
vis.resize(N);
}
signed DistanceSum(signed N, signed *X, signed *Y) {
init(N);
for (int i = 0; i < N; i++)
appr[pii(X[i], Y[i])] = i;
int mnX = INF, mxX = 0, mnY = INF, mxY = 0;
for (int i = 0; i < N; i++) {
mnX = min(mnX, (int)X[i]);
mnY = min(mnY, (int)Y[i]);
mxX = max(mxX, (int)X[i]);
mxY = max(mxY, (int)Y[i]);
for (int j = 0; j < 4; j++) {
if (appr.count(pii(X[i]+dx[j], Y[i]+dy[j]))) {
int id = appr[pii(X[i]+dx[j], Y[i]+dy[j])];
path[id].pb(i);
path[i].pb(id);
}
}
}
int ans = 0;
if ((mxX - mnX + 1) * (mxY - mnY + 1) != N) {
for (int i = 0; i < N; i++)
ans = (ans + BFS(i, N)) % MOD;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2668 KB |
Output is correct |
5 |
Correct |
3 ms |
2668 KB |
Output is correct |
6 |
Correct |
4 ms |
2668 KB |
Output is correct |
7 |
Correct |
3 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2668 KB |
Output is correct |
9 |
Correct |
3 ms |
2668 KB |
Output is correct |
10 |
Correct |
3 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
2796 KB |
Output is correct |
2 |
Correct |
45 ms |
2924 KB |
Output is correct |
3 |
Correct |
88 ms |
2924 KB |
Output is correct |
4 |
Correct |
80 ms |
2992 KB |
Output is correct |
5 |
Correct |
141 ms |
3052 KB |
Output is correct |
6 |
Correct |
179 ms |
3180 KB |
Output is correct |
7 |
Correct |
139 ms |
3052 KB |
Output is correct |
8 |
Correct |
149 ms |
3080 KB |
Output is correct |
9 |
Correct |
153 ms |
3052 KB |
Output is correct |
10 |
Correct |
168 ms |
3180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1081 ms |
6124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
5740 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |