Submission #58501

#TimeUsernameProblemLanguageResultExecution timeMemory
58501E869120Towns (IOI15_towns)C++14
48 / 100
26 ms1812 KiB
#include "towns.h" #include <iostream> #include <cmath> #include <vector> #include <algorithm> using namespace std; int Dist[111][111], cu[111], cv[111], hub[111], Queries = 0; //int getDistance(int p1, int p2) { Queries++; return Weight[p1][p2]; } int getDist(int p1, int p2) { if (p1 == p2) return 0; if (p1 > p2) swap(p1, p2); if (Dist[p1][p2] == -1) { Dist[p1][p2] = getDistance(p1, p2); } return Dist[p1][p2]; } int hubDistance(int N, int sub) { for (int i = 0; i < 111; i++) { for (int j = 0; j < 111; j++) Dist[i][j] = -1; cu[i] = 0; cv[i] = 0; hub[i] = 0; } int maxn1 = 0, u = 0; for (int i = 0; i < N; i++) { int V = getDist(0, i); if (V > maxn1) { maxn1 = V; u = i; } } int maxn2 = 0, v = 0; for (int i = 0; i < N; i++) { int V = getDist(u, i); if (V > maxn2) { maxn2 = V; v = i; } cu[i] = V; } for (int i = 0; i < N; i++) cv[i] = getDist(v, i); int ret = (1 << 30), maxid = 0; for (int i = 0; i < N; i++) { if (abs(cu[i] - cv[i]) < ret) { ret = abs(cu[i] - cv[i]); maxid = i; } } int p[3] = { 0,0,0 }, R = cu[maxid] - cv[maxid], S = (maxn2 + ret) / 2; vector<int>vec; R = abs(R); for (int i = 0; i < N; i++) { if (cu[i] - cv[i] < -R) p[0]++; if (cu[i] - cv[i] >= -R && cu[i] - cv[i] <= R) { p[1]++; vec.push_back(i); } if (cu[i] - cv[i] > R) p[2]++; } if (sub == 1 || sub == 2 || sub == 4) { if (p[0] > (N / 2) || p[1] > (N / 2) || p[2] >(N / 2)) return -S; return S; } if (sub == 3) { if (p[0] > (N / 2) || p[2] > (N / 2)) return -S; for (int i = 0; i < vec.size(); i++) hub[vec[i]] = max(cu[vec[i]], cv[vec[i]]) - S; int deg[111]; for (int i = 0; i < 111; i++) deg[i] = 0; // vec は同じやつのリスト int F = 0; for (int i = 0; i < vec.size(); i++) { if (deg[i] >= 1) continue; for (int j = 0; j < vec.size(); j++) { if (deg[j] >= 1) continue; int Z = getDist(vec[i], vec[j]); if (Z >= hub[vec[i]] + hub[vec[j]]) continue; deg[i]++; if (i != j) deg[j]++; F++; if (deg[i] > (N / 2)) return -S; //if (F >= (N / 2)) return S; } } return S; } return 0; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:47:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); i++) hub[vec[i]] = max(cu[vec[i]], cv[vec[i]]) - S;
                   ~~^~~~~~~~~~~~
towns.cpp:53:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); i++) {
                   ~~^~~~~~~~~~~~
towns.cpp:55:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < vec.size(); j++) {
                    ~~^~~~~~~~~~~~
#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...