Submission #18844

#TimeUsernameProblemLanguageResultExecution timeMemory
18844ggohIdeal city (IOI12_city)C++98
0 / 100
24 ms9444 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...