Submission #761624

#TimeUsernameProblemLanguageResultExecution timeMemory
761624SanguineChameleonIdeal city (IOI12_city)C++17
11 / 100
1083 ms1876 KiB
#include <bits/stdc++.h> using namespace std; const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; int DistanceSum(int N, int *X, int *Y) { int res = 0; for (int i = 0; i < N; i++) { map<pair<int, int>, int> dist; for (int j = 0; j < N; j++) { if (j != i) { dist[make_pair(X[j], Y[j])] = 0; } } dist[make_pair(X[i], Y[i])] = 1; deque<pair<int, int>> Q; Q.emplace_back(X[i], Y[i]); while (!Q.empty()) { int cx = Q.front().first; int cy = Q.front().second; Q.pop_front(); int cur = dist[make_pair(cx, cy)]; res += cur - 1; for (int d = 0; d < 4; d++) { int nx = cx + dx[d]; int ny = cy + dy[d]; auto it = dist.find(make_pair(nx, ny)); if (it != dist.end() && it->second == 0) { dist[make_pair(nx, ny)] = cur + 1; Q.emplace_back(nx, ny); } } } } return res / 2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...