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>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, M = 1000000000;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
void add(int& a, int b) {
a += b;
if(a >= M) a -= M;
}
int brute(int n, int* x, int* y) {
V<vi> G(n);
map<pi, int> mp;
for(int i = 0; i < n; i++)
mp[{x[i], y[i]}] = i;
for(int i = 0; i < n; i++) {
for(int _ = 0; _ < 4; _++) {
int xx = x[i] + dx[_], yy = y[i] + dy[_];
if(mp.count({xx, yy})) {
G[i].PB(mp[{xx, yy}]);
}
}
}
int ans = 0;
auto bfs = [&] (int s) {
queue<int> q;
vi d(n, -1);
q.push(s), d[s] = 0;
while(q.size()) {
int u = q.front(); q.pop();
if(u < s) add(ans, d[u]);
for(int v:G[u]) if(d[v] == -1) {
d[v] = d[u] + 1;
q.push(v);
}
}
};
for(int i = 0; i < n; i++) {
bfs(i);
}
return ans;
}
int convex(int n, int* x, int *y) {
}
int DistanceSum(int n, int *x, int *y) {
if(n <= 2000) {
return brute(n, x, y);
} else {
return convex(n, x, y);
}
}
Compilation message (stderr)
city.cpp: In function 'int convex(int, int*, int*)':
city.cpp:61:1: warning: no return statement in function returning non-void [-Wreturn-type]
61 | }
| ^
# | 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... |