Submission #288517

#TimeUsernameProblemLanguageResultExecution timeMemory
288517SaboonTowns (IOI15_towns)C++17
13 / 100
22 ms504 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int inf = 2e8 + 10; int n, d[110][110]; int cnt[110]; int Dis(int v, int u){ if (v == u or d[v][u] > 0) return d[v][u]; return d[v][u] = d[u][v] = getDistance(v,u); } int getDis(int v, int u, int w){ return (Dis(v,u)+Dis(v,w)-Dis(u,w))/2; } int hubDistance(int N, int sub){ memset(d, 0, sizeof d); n = N; int Q1 = 0, Q2 = 0; for (int i = 1; i < n; i++) if (Dis(0,i) > Dis(0,Q1)) Q1 = i; for (int i = 1; i < n; i++) if (Dis(Q1,i) > Dis(Q1,Q2)) Q2 = i; int R = inf; vector<int> a; for (int v = 0; v < n; v++){ if (v == Q1 or v == Q2) continue; int A = getDis(Q1, Q2, v), B = getDis(Q2, Q1, v); a.push_back(A); R = min(R,max(A,B)); } sort(a.begin(), a.end()); a.resize(unique(a.begin(),a.end())-a.begin()); int m = 1; for (auto it : a){ int now = 0; vector<int> b; for (int v = 0; v < n; v++){ if (v == Q1 or v == Q2) continue; if (getDis(Q1, Q2, v) == it) now ++, b.push_back(v); } int t = max(it,Dis(Q1,Q2)-it); if (t != R or m > n/2 or (n-m-now) > n/2){ m += now; continue; } if (now <= n/2) return R; memset(cnt, 0, sizeof cnt); vector<int> nom; shuffle(b.begin(), b.end(), rng); nom.push_back(b[0]); cnt[b[0]] ++; int Constant = 8, check = -1; for (int i = 1; i < now; i++){ if (i <= Constant){ bool found = 0; for (auto j : nom) if (getDis(Q1,j,b[i]) > it) cnt[j] ++, found = 1; if (!found) nom.push_back(b[i]), cnt[b[i]] ++; if (i == Constant){ sort(nom.begin(), nom.end(), [](int x, int y){return cnt[x] > cnt[y];}); check = nom[0]; } } else{ if (getDis(Q1,check,b[i]) == it) cnt[check] ++; } } if (cnt[check] <= n/2) return R; m += now; } return -R; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:19:28: warning: unused parameter 'sub' [-Wunused-parameter]
   19 | int hubDistance(int N, int sub){
      |                        ~~~~^~~
#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...