제출 #428860

#제출 시각아이디문제언어결과실행 시간메모리
428860wiwiho이상적인 도시 (IOI12_city)C++14
11 / 100
1090 ms2892 KiB
#include <bits/stdc++.h> #define mp make_pair #define F first #define S second using namespace std; typedef long long ll; using pii = pair<int, int>; const ll MOD = 1000000000; int n; vector<pii> city; set<pii> g; vector<pii> dir = {mp(1, 0), mp(0, 1), mp(-1, 0), mp(0, -1)}; ll bfs(pii st){ map<pii, ll> dis; dis[st] = 0; queue<pii> q; q.push(st); ll ans = 0; while(!q.empty()){ pii now = q.front(); ans += dis[now]; q.pop(); for(pii d : dir){ pii go = mp(now.F + d.F, now.S + d.S); if(g.find(go) == g.end()) continue; if(dis.find(go) != dis.end()) continue; dis[go] = dis[now] + 1; q.push(go); } } return ans; } int DistanceSum(int N, int *X, int *Y){ n = N; city.resize(n); for(int i = 0; i < n; i++){ city[i] = mp(X[i], Y[i]); g.insert(mp(X[i], Y[i])); } ll ans = 0; for(pii i : city){ ans += bfs(i); } 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...