Submission #880550

#TimeUsernameProblemLanguageResultExecution timeMemory
880550edogawa_somethingIdeal city (IOI12_city)C++17
0 / 100
1065 ms5196 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vii; typedef pair<ll,ll> pii; #define F first #define S second #define pb push_back #define all(v) v.begin(),v.end() const ll dx[4]={1,-1,0,0}; const ll dy[4]={0,0,1,-1}; const ll M=1e5+6; const ll mod=1e9; ll n; map<pii,ll>mp; bool vis[M]; vii v[M]; ll bfs(ll x){ for(int i=0;i<n;i++) vis[i]=0; queue<pii>q; q.push({0,x}); ll res=0; while(!q.empty()){ pii p=q.front(); q.pop(); if(vis[p.S]) continue; res+=p.F; vis[p.S]=1; for(auto it:v[p.S]){ if(!vis[it]) q.push({p.F+1,it}); } } return res; } int DistanceSum(int N, int *X, int *Y) { n=N; for(int i=0;i<n;i++){ mp[{X[i],Y[i]}]=i+1; } for(auto &it:mp){ for(ll i=0;i<4;i++){ if(mp.find({it.F.F+dx[i],it.F.S+dy[i]})!=mp.end()) v[it.S].pb(mp[{it.F.F+dx[i],it.F.S+dy[i]}]); } } ll ans=0; for(int i=1;i<=n;i++){ ans+=bfs(i); ans%=mod; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...