Submission #1021770

#TimeUsernameProblemLanguageResultExecution timeMemory
1021770vjudge1Ideal city (IOI12_city)C++17
34 / 100
1028 ms2080 KiB
#include<bits/stdc++.h> using namespace std; int mod=1e9; long long ANS; set<pair<int,int>>st; queue<tuple<int,int,int>>q; void flod(){ if(q.empty())return; auto[x,y,d]=q.front(); q.pop(); if(!st.count({x,y}))return flod(); st.erase({x,y}); ANS+=d; q.emplace(x-1,y,d+1); q.emplace(x+1,y,d+1); q.emplace(x,y-1,d+1); q.emplace(x,y+1,d+1); flod(); } int DistanceSum(int N, int *X, int *Y) { if(N>2000){ sort(X,X+N); sort(Y,Y+N); long long ans=0; for(long long i=0;i<N;i++){ ans+=i*X[i] - (N-i-1) *X[i]; ans%=mod; } for(long long i=0;i<N;i++){ ans+=i*Y[i] - (N-i-1) *Y[i]; ans%=mod; } return (ans+mod)%mod; } int A=*min_element(Y,Y+N); int B=*min_element(X,X+N); for(int i=0;i<N;i++) st.insert({X[i]-=B,Y[i]-=A}); set<pair<int,int>>st2=st; for(int i=0;i<N;i++){ q.emplace(X[i],Y[i],0); flod(); st=st2; } return ANS/2%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...