Submission #764768

#TimeUsernameProblemLanguageResultExecution timeMemory
764768SanguineChameleonTowns (IOI15_towns)C++17
35 / 100
12 ms404 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1e2 + 20; int memo[maxN][maxN]; int depth[maxN]; bool flag[maxN]; int dist(int u, int v) { if (memo[u][v] != -1) { return memo[u][v]; } else { return memo[u][v] = memo[v][u] = getDistance(u, v); } } int hubDistance(int N, int sub) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { memo[i][j] = (i == j ? 0 : -1); } } int X = 0; for (int i = 0; i < N; i++) { if (dist(0, i) > dist(0, X)) { X = i; } } int Y = 0; for (int i = 0; i < N; i++) { if (dist(X, i) > dist(X, Y)) { Y = i; } } int R = dist(X, Y); map<int, vector<int>> comps; for (int i = 0; i < N; i++) { depth[i] = (dist(X, i) + dist(Y, i) - dist(X, Y)) / 2; int left = dist(X, i) - depth[i]; int right = dist(Y, i) - depth[i]; comps[left].push_back(i); R = min(R, max(left, right)); } int pref = 0; int suf = N; for (auto p: comps) { suf -= (int)p.second.size(); if (max(p.first, dist(X, Y) - p.first) == R && pref <= N / 2 && suf <= N / 2) { if ((int)p.second.size() <= N / 2) { return R; } if (sub != 1 && sub != 2 && sub != 4) { bool ok = true; for (auto u: p.second) { if (flag[u]) { continue; } flag[u] = true; int sz = 0; deque<int> q; q.push_back(u); while (!q.empty()) { int u = q.front(); q.pop_front(); sz++; for (auto v: p.second) { if (!flag[v] && depth[u] + depth[v] != dist(u, v)) { flag[v] = true; q.push_back(v); } } } if (sz > N / 2) { ok = false; break; } } if (ok) { return R; } } } pref += (int)p.second.size(); } return -R; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:65:11: warning: declaration of 'u' shadows a previous local [-Wshadow]
   65 |       int u = q.front();
      |           ^
towns.cpp:56:15: note: shadowed declaration is here
   56 |     for (auto u: p.second) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...