# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
424018 | cfalas | Ideal city (IOI12_city) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000000
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
vi a, b;
ii diag[4] = {{0,-1}, {0,1}, {-1,0}, {1,0}};
#include <boost/functional/hash.hpp>
int DistanceSum(int n, int *X, int *Y) {
unordered_set<ii, boost::hash<ii>> avail;
FOR(i,n){
avail.insert({X[i], Y[i]});
}
int ans=0;
FOR(i,n){
// bfs from i
unordered_set<ii, boost::hash<ii> > used;
queue<ii> q;
q.push({X[i], Y[i]});
used.insert({X[i], Y[i]});
q.push({-1,-1});
int d=0;
//cout<<X[i]<<" "<<Y[i]<<": "<<endl;
while(q.size()>1){
ii t= q.front();
q.pop();
if(t.F==-1 && t.S==-1){
d++;
q.push({-1,-1});
continue;
}
//cout<<t.F<<" "<<t.S<<" "<<d<<endl;
ans+=d;
ans%=MOD;
FOA(v,diag){
ii x = {v.F+t.F, v.S+t.S};
if(avail.count(x) && !used.count(x)){
q.push(x);
used.insert(x);
}
}
}
}
return ans/2;
}