#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
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 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
340 KB |
Output is correct |
2 |
Correct |
25 ms |
452 KB |
Output is correct |
3 |
Correct |
56 ms |
500 KB |
Output is correct |
4 |
Correct |
55 ms |
512 KB |
Output is correct |
5 |
Correct |
94 ms |
468 KB |
Output is correct |
6 |
Correct |
92 ms |
468 KB |
Output is correct |
7 |
Correct |
100 ms |
572 KB |
Output is correct |
8 |
Correct |
95 ms |
564 KB |
Output is correct |
9 |
Correct |
93 ms |
564 KB |
Output is correct |
10 |
Correct |
89 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
3016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1081 ms |
3020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |