Submission #115653

#TimeUsernameProblemLanguageResultExecution timeMemory
115653E869120Towns (IOI15_towns)C++14
61 / 100
20 ms1048 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; int N, dist[183][179]; int getdist(int u, int v) { if (u == v) return 0; if (dist[u][v] >= 1) return dist[u][v] - 1; int R = getDistance(u, v); dist[u][v] = R + 1; dist[v][u] = R + 1; return R; } pair<int, int> Furthest(int pos) { int maxn = -1, maxid = -1; for (int i = 0; i < N; i++) { int D = getdist(pos, i); if (D > maxn) { maxn = D; maxid = i; } } return make_pair(maxn, maxid); } bool isdifferent(int root, int dst, int u1, int u2) { int V1 = getdist(root, u1); V1 -= dst; int V2 = getdist(root, u2); V2 -= dst; int V3 = getdist(u1, u2); if (V1 + V2 == V3) return true; return false; } int exact_size(int root, int dst, vector<int> vec) { vector<int> vec2 = vec; int last = -1; while (vec2.size() >= 2) { vector<int> vec3; for (int i = 0; i < (int)vec2.size() - 1; i += 2) { bool I = isdifferent(root, dst, vec2[i], vec2[i + 1]); if (I == false) vec3.push_back(vec2[i]); } if (vec2.size() % 2 == 1) last = vec2[vec2.size() - 1]; vec2 = vec3; } int C = last; if (vec2.size() >= 1) C = vec2[0]; if (C == -1) return 1; int cnt = 0; for (int i = 0; i < vec.size(); i++) { bool I = isdifferent(root, dst, C, vec[i]); if (I == false) cnt++; } return cnt; } int hubDistance(int NN, int sub) { for (int i = 0; i < NN * NN; i++) dist[i / NN][i % NN] = 0; N = NN; pair<int, int> E1 = Furthest(0); pair<int, int> E2 = Furthest(E1.second); int diameter = E2.first, u1 = E1.second, u2 = E2.second, minx = (1 << 30); for (int i = 0; i < N; i++) { minx = min(minx, abs(getdist(u1, i) - getdist(u2, i))); } vector<int> t[4]; for (int i = 0; i < N; i++) { int V1 = getdist(u1, i); int V2 = getdist(u2, i); if (V1 < V2) { if (abs(V1 - V2) == minx) t[1].push_back(i); else t[0].push_back(i); } if (V1 >= V2) { if (abs(V1 - V2) == minx) t[2].push_back(i); else t[3].push_back(i); } } int E[4] = {(int)t[0].size(), (int)t[1].size(), (int)t[2].size(), (int)t[3].size()}; if (sub == 3 || sub == 5) { if (t[1].size() > N / 2) { int s = (getdist(u1, u2) + getdist(u1, t[1][0]) - getdist(u2, t[1][0])) / 2; E[1] = exact_size(u1, s, t[1]); } if (t[2].size() > N / 2) { int s = (getdist(u1, u2) + getdist(u1, t[2][0]) - getdist(u2, t[2][0])) / 2; E[2] = exact_size(u1, s, t[2]); } } bool flag = false; if (E[1] >= 1 && max({E[0], E[1], (int)t[2].size() + E[3]}) <= N / 2) flag = true; if (E[2] >= 1 && max({E[0] + (int)t[1].size(), E[2], E[3]}) <= N / 2) flag = true; if (flag == true) return (diameter + minx) / 2; return -1 * ((diameter + minx) / 2); }

Compilation message (stderr)

towns.cpp: In function 'int exact_size(int, int, std::vector<int>)':
towns.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vec.size(); i++) {
                  ~~^~~~~~~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (t[1].size() > N / 2) { int s = (getdist(u1, u2) + getdist(u1, t[1][0]) - getdist(u2, t[1][0])) / 2; E[1] = exact_size(u1, s, t[1]); }
       ~~~~~~~~~~~~^~~~~~~
towns.cpp:85:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (t[2].size() > N / 2) { int s = (getdist(u1, u2) + getdist(u1, t[2][0]) - getdist(u2, t[2][0])) / 2; E[2] = exact_size(u1, s, t[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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...