Submission #1018487

#TimeUsernameProblemLanguageResultExecution timeMemory
1018487pccIdeal city (IOI12_city)C++17
32 / 100
82 ms3416 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second const int mod = 1e9; const int mxn = 1e5+10; vector<int> paths[mxn]; vector<pii> v; namespace SUB1{ int N; int dist[mxn]; queue<int> q; int BFS(int now){ memset(dist,-1,sizeof(dist)); dist[now] = 0; q.push(now); while(!q.empty()){ auto now = q.front(); q.pop(); for(auto nxt:paths[now]){ if(dist[nxt] == -1){ dist[nxt] = dist[now]+1; q.push(nxt); } } } int re = 0; for(int i = 0;i<N;i++)re = (re+dist[i])%mod; return re; } int GO(int NN,int* xx,int *yy){ N = NN; for(int i = 0;i<N;i++){ v.push_back(pii(xx[i],yy[i])); } vector<int> perm; for(int i = 0;i<N;i++)perm.push_back(i); sort(perm.begin(),perm.end(),[](int a,int b){return v[a].fs == v[b].fs?v[a].sc<v[b].sc:v[a].fs<v[b].fs;}); for(int i = 1;i<N;i++){ int now = perm[i],pre = perm[i-1]; if(v[now].fs == v[pre].fs&&v[now].sc == v[pre].sc+1){ paths[now].push_back(pre); paths[pre].push_back(now); } } sort(perm.begin(),perm.end(),[](int a,int b){return v[a].sc == v[b].sc?v[a].fs<v[b].fs:v[a].sc<v[b].sc;}); for(int i = 1;i<N;i++){ int now = perm[i],pre = perm[i-1]; if(v[now].sc == v[pre].sc&&v[now].fs == v[pre].fs+1){ paths[now].push_back(pre); paths[pre].push_back(now); } } int ans = 0; for(int i = 0;i<N;i++){ ans += BFS(i); ans %= mod; } return ans>>1; } } namespace SUB2{ int GO(int NN,int *X,int *Y){ return -1; } } int DistanceSum(int N, int *X, int *Y) { if(N<=2000)return SUB1::GO(N,X,Y); else return SUB2::GO(N,X,Y); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...