Submission #761626

#TimeUsernameProblemLanguageResultExecution timeMemory
761626SanguineChameleonIdeal city (IOI12_city)C++17
32 / 100
1085 ms16468 KiB
#include <bits/stdc++.h> using namespace std; const int maxN = 2e3 + 20; const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; int dist[maxN][maxN]; int DistanceSum(int N, int *X, int *Y) { fill_n(&dist[0][0], maxN * maxN, -1); int min_X = X[0]; for (int i = 0; i < N; i++) { min_X = min(min_X, X[i]); } for (int i = 0; i < N; i++) { X[i] -= min_X - 1; } int min_Y = Y[0]; for (int i = 0; i < N; i++) { min_Y = min(min_Y, Y[i]); } for (int i = 0; i < N; i++) { Y[i] -= min_Y - 1; } int res = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[X[j]][Y[j]] = 0; } dist[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[cx][cy]; res += cur - 1; for (int d = 0; d < 4; d++) { int nx = cx + dx[d]; int ny = cy + dy[d]; if (dist[nx][ny] == 0) { dist[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...