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<cstdio>
#include<map>
#include<queue>
int a,x,y,p,q,i,j,r,u,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
long long sum,mod=1e9;
std::map<int,int>m[100002];
int D[100002];
long long S[100002];
std::queue<int>P,Q;
int DistanceSum (int N, int *X, int *Y)
{
a=N;
x=2147483647;y=2147483647;
for(i=a-1;i>=0;i--)X[i+1]=X[i],Y[i+1]=Y[i];
for(i=1;i<=a;i++)x=std::min(x,X[i]),y=std::min(y,Y[i]);
for(i=1;i<=a;i++)X[i]-=x,Y[i]-=y,m[X[i]][Y[i]]=i;
P.push(X[1]);Q.push(Y[1]);
D[1]=1;S[1]++;
while(!P.empty())
{
p=P.front();P.pop();
q=Q.front();Q.pop();
r=m[p][q];
for(int k=0;k<4;k++)
{
x=p+dx[k];
y=q+dy[k];
if(x>=0&&y>=0&&m[x][y])
{
u=m[x][y];
if(D[u]==0)
{
D[u]=D[r]+1;
S[1]+=D[u];
P.push(x);Q.push(y);
}
}
}
}
S[1]/=(long long)2;
return sum%mod;
}
# | 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... |