Submission #64132

#TimeUsernameProblemLanguageResultExecution timeMemory
64132VahanIdeal city (IOI12_city)C++17
100 / 100
451 ms230424 KiB
#include<vector> #include<queue> #include<iostream> using namespace std; vector<pair<long long,long long> > g[3000000]; vector<long long> tx[3000000],ty[3000000]; long long sx[3000000],sy[3000000],xq[3000000],yq[3000000],n,u[3000000],xh,yh,xg[3000000],yg[3000000]; queue<long long> q; long long pa=0; long long mod=1000000000; long long kax(long long x,long long y) { for(long long i=0;i<tx[x].size();i++) { long long to=tx[x][i]; if(to==y) return 0; } return 1; } long long kay(long long x,long long y) { for(long long i=0;i<ty[x].size();i++) { long long to=ty[x][i]; if(to==y) return 0; } return 1; } long long ka(long long x,long long y) { long long in=-1; for(long long i=0;i<g[x].size();i++) { long long to=g[x][i].first; long long ind=g[x][i].second; if(to==y) { in=ind; break; } } return in; } void dfsx(long long v,long long p) { sx[v]=xq[v]; long long r=0,l=0; for(long long i=0;i<tx[v].size();i++) { long long to=tx[v][i]; if(to==p) continue; dfsx(to,v); sx[v]+=sx[to]; pa+=(sx[to]*(n-sx[to]))%mod; pa%=mod; } } void dfsy(long long v,long long p) { sy[v]=yq[v]; for(long long i=0;i<ty[v].size();i++) { long long to=ty[v][i]; if(to==p) continue; dfsy(to,v); sy[v]+=sy[to]; pa+=(sy[to]*(n-sy[to]))%mod; pa%=mod; } } long long DistanceSum(int N, int *X, int *Y) { n=N; for(long long i=0;i<n;i++) g[X[i]].push_back(make_pair(Y[i],i)); for(long long i=0;i<n;i++) { if(u[i]==0) { long long x=X[i],y=Y[i]; xg[i]=xh; xq[xh]++; long long t=1; while(1) { long long aa=ka(x+t,y); if(aa==-1) break; xg[aa]=xh; if(xg[0]==6) cout<<"000000"<<x<<" "<<y<<endl; xq[xh]++; u[aa]=1; t++; } t=1; while(1) { long long aa=ka(x-t,y); if(aa==-1) break; xg[aa]=xh; if(xg[0]==6) cout<<"0000"<<x<<" "<<y<<endl; xq[xh]++; u[aa]=1; t++; } xh++; } } for(long long i=0;i<n;i++) u[i]=0; for(long long i=0;i<n;i++) { if(u[i]==0) { long long x=X[i],y=Y[i]; yg[i]=yh; yq[yh]++; long long t=1; while(1) { long long aa=ka(x,y+t); if(aa==-1) break; yg[aa]=yh; yq[yh]++; u[aa]=1; t++; } t=1; while(1) { long long aa=ka(x,y-t); if(aa==-1) break; yg[aa]=yh; yq[yh]++; u[aa]=1; t++; } yh++; } } for(long long i=0;i<n;i++) { long long x=X[i],y=Y[i]; long long e=ka(x+1,y); if(e!=-1 && kay(yg[i],yg[e])) ty[yg[i]].push_back(yg[e]); e=ka(x-1,y); if(e!=-1 && kay(yg[i],yg[e])) ty[yg[i]].push_back(yg[e]); e=ka(x,y+1); if(e!=-1 && kax(xg[i],xg[e])) tx[xg[i]].push_back(xg[e]); e=ka(x,y-1); if(e!=-1 && kax(xg[i],xg[e])) tx[xg[i]].push_back(xg[e]); } dfsx(0,-1); dfsy(0,-1); return pa; }

Compilation message (stderr)

city.cpp: In function 'long long int kax(long long int, long long int)':
city.cpp:13:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<tx[x].size();i++)
                       ~^~~~~~~~~~~~~
city.cpp: In function 'long long int kay(long long int, long long int)':
city.cpp:23:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<ty[x].size();i++)
                       ~^~~~~~~~~~~~~
city.cpp: In function 'long long int ka(long long int, long long int)':
city.cpp:34:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<g[x].size();i++)
                       ~^~~~~~~~~~~~
city.cpp: In function 'void dfsx(long long int, long long int)':
city.cpp:50:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<tx[v].size();i++)
                       ~^~~~~~~~~~~~~
city.cpp:49:15: warning: unused variable 'r' [-Wunused-variable]
     long long r=0,l=0;
               ^
city.cpp:49:19: warning: unused variable 'l' [-Wunused-variable]
     long long r=0,l=0;
                   ^
city.cpp: In function 'void dfsy(long long int, long long int)':
city.cpp:64:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<ty[v].size();i++)
                       ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...