#include <bits/stdc++.h>
#define LL long long
#define pll pair<LL,LL>
using namespace std;
const int MOD = 1000000000;
struct ci{
LL x,y;
int nea[4]={-1,-1,-1,-1};
}inf[2222];
LL n,sum;
LL x[2222],y[2222];
map<pll,int> mp;
queue<int> qi,qd;
bool used[2222];
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};
void bfs(int v,int d){
qi.push(v);
qd.push(d);
used[v]=true;
while(!qi.empty()){
int pi=qi.front(); qi.pop();
int pd=qd.front(); qd.pop();
sum=(sum+pd)%(MOD*2);
for(int i=0;i<4;i++){
if(inf[pi].nea[i]!=-1 && !used[inf[pi].nea[i]]){
qi.push(inf[pi].nea[i]);
qd.push(pd+1);
used[inf[pi].nea[i]]=1;
}
}
}
}
int DistanceSum(int N,int *X,int *Y){
n=N;
for(int i=0;i<N;i++) x[i]=X[i];
for(int i=0;i<N;i++) y[i]=Y[i];
for(int i=0;i<n;i++) mp.insert({{x[i],y[i]},i});
for(int i=0;i<n;i++){
inf[i].x=x[i];
inf[i].y=y[i];
for(int j=0;j<4;j++){
int nx=x[i]+dx[j];
int ny=y[i]+dy[j];
map<pll,int>::iterator it=mp.find({nx,ny});
if(it!=mp.end()) inf[i].nea[j]=it->second;
}
}
if(n<=2000){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) used[j]=0;
bfs(i,0);
}
return sum/2;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
4 ms |
656 KB |
Output is correct |
8 |
Correct |
4 ms |
656 KB |
Output is correct |
9 |
Correct |
4 ms |
840 KB |
Output is correct |
10 |
Correct |
3 ms |
840 KB |
Output is correct |
11 |
Correct |
4 ms |
840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
840 KB |
Output is correct |
2 |
Correct |
29 ms |
840 KB |
Output is correct |
3 |
Correct |
78 ms |
888 KB |
Output is correct |
4 |
Correct |
69 ms |
928 KB |
Output is correct |
5 |
Correct |
148 ms |
1144 KB |
Output is correct |
6 |
Correct |
96 ms |
1172 KB |
Output is correct |
7 |
Correct |
149 ms |
1172 KB |
Output is correct |
8 |
Correct |
100 ms |
1172 KB |
Output is correct |
9 |
Correct |
94 ms |
1172 KB |
Output is correct |
10 |
Correct |
98 ms |
1184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
1760 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
1884 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |