#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9;
int DistanceSum(int N, int *X, int *Y){
vector<int> g[N];
map<pair<int, int>, int> s;
for(int i = 0;i < N;i++){
auto p = s.find({X[i]-1, Y[i]});
if(p != s.end()) {
g[i].push_back(p->second);
g[p->second].push_back(i);
}
p = s.find({X[i]+1, Y[i]});
if(p != s.end()) {
g[i].push_back(p->second);
g[p->second].push_back(i);
}
p = s.find({X[i], Y[i]-1});
if(p != s.end()) {
g[i].push_back(p->second);
g[p->second].push_back(i);
}
p = s.find({X[i], Y[i]+1});
if(p != s.end()) {
g[i].push_back(p->second);
g[p->second].push_back(i);
}
s[{X[i], Y[i]}] = i;
}
long long ans = 0;
int d[N];
for(int i = 0;i < N;i++){
memset(d, 0, sizeof(d));
for(int j = 0;j < i;j++) d[j] = 1;
queue<int> q;
q.push(i);
while(!q.empty()){
int t = q.front();
q.pop();
for(int j : g[t]){
if(j != i && !d[j]){
d[j] = d[t]+1;
ans = (ans+d[j])%MOD;
q.push(j);
}
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
3008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
178 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |