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>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int i,j,k;
unordered_map<long long,int>um;
long long dist[2222][2222],ans;
long long f(int x,int y)
{
return (long long)y+((long long)x<<31);
}
int DistanceSum(int n, int *x, int *y) {
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
dist[i][j]=4294967296ll;
for(i=0;i<n;i++)
{
um[f(x[i],y[i])]=i+1;
for(j=0;j<4;j++)
{
if(um[f(x[i]+dx[j],y[i]+dy[j])])
{
dist[i+1][um[f(x[i]+dx[j],y[i]+dy[j])]]=1;
dist[um[f(x[i]+dx[j],y[i]+dy[j])]][i+1]=1;
}
}
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i!=j)
{
//printf("dist[%d][%d]=%d\n",i,j,dist[i][j]);
ans+=dist[i][j];
}
return (ans/2)%1000000000;
}
# | 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... |