#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
/// #define int ll
const int MOD = 1e9;
vector<int> adj[100001];
int DistanceSum(int N, int X[], int Y[]) {
for(int l = 0; l < N; l++) {
for(int i = l + 1; i < N; i++) {
if(X[l] == X[i] && abs(Y[l] - Y[i]) == 1)
adj[l].pb(i), adj[i].pb(l);
if(Y[l] == Y[i] && abs(X[l] - X[i]) == 1)
adj[l].pb(i), adj[i].pb(l);
}
}
ll res = 0;
for(int l = 0; l < N; l++) {
vector<int> dist(N, -1);
queue<int> q; q.push(l); dist[l] = 0;
while(!q.empty()) {
int v = q.front(); q.pop();
if(v > l) res = (res % MOD + dist[v] % MOD) % MOD;
for(auto u : adj[v]) {
if(dist[u] != -1) continue;
dist[u] = dist[v] + 1;
q.push(u);
}
}
}
return res % MOD;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2660 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
3 ms |
2644 KB |
Output is correct |
7 |
Correct |
3 ms |
2644 KB |
Output is correct |
8 |
Correct |
3 ms |
2656 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2652 KB |
Output is correct |
11 |
Correct |
4 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2644 KB |
Output is correct |
2 |
Correct |
30 ms |
2688 KB |
Output is correct |
3 |
Correct |
61 ms |
2644 KB |
Output is correct |
4 |
Correct |
62 ms |
2712 KB |
Output is correct |
5 |
Correct |
106 ms |
2740 KB |
Output is correct |
6 |
Correct |
115 ms |
2744 KB |
Output is correct |
7 |
Correct |
125 ms |
2748 KB |
Output is correct |
8 |
Correct |
144 ms |
2748 KB |
Output is correct |
9 |
Correct |
114 ms |
2744 KB |
Output is correct |
10 |
Correct |
110 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1080 ms |
3620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
3684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |