Submission #1028309

#TimeUsernameProblemLanguageResultExecution timeMemory
1028309huutuanTowns (IOI15_towns)C++14
25 / 100
15 ms1188 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; int dd[200][200], d1[200], d2[200]; mt19937 rng(69420); int GetDistance(int u, int v){ if (u==v) return 0; if (dd[u][v]) return dd[u][v]; int tmp=getDistance(u, v); dd[u][v]=tmp; dd[v][u]=tmp; return tmp; } int hubDistance(int N, int sub) { memset(dd, 0, sizeof dd); memset(d1, 0, sizeof d1); memset(d2, 0, sizeof d2); int u=0, dis=0; for (int i=1; i<N; ++i){ int d=GetDistance(0, i); if (d>dis){ dis=d; u=i; } } dis=0; int v=u; for (int i=0; i<N; ++i) if (i!=u){ int d=GetDistance(u, i); d1[i]=d; if (d>dis){ dis=d; v=i; } } int ans=1e9; vector<pair<int, int>> vv; for (int i=0; i<N; ++i) if (i!=u && i!=v){ d2[i]=GetDistance(v, i); int common=(d1[i]+d2[i]-dis)/2; int dl=d1[i]-common, dr=d2[i]-common; ans=min(ans, max(dl, dr)); vv.emplace_back(dl, dr); } if (sub<=2) return ans; d1[u]=d2[v]=0; d1[v]=d2[u]=dis; sort(vv.begin(), vv.end()); vv.resize(unique(vv.begin(), vv.end())-vv.begin()); int cnt=0; for (auto &ii:vv) if (max(ii.first, ii.second)==ans) ++cnt; int mx=N/2; for (auto &ii:vv) if (max(ii.first, ii.second)==ans){ int szl=0, szr=0; vector<pair<int, int>> child; for (int i=0; i<N; ++i){ int common=(d1[i]+d2[i]-dis)/2; int dl=d1[i]-common, dr=d2[i]-common; if (dl<ii.first) ++szl; else if (dl>ii.first) ++szr; else child.emplace_back(i, 1); } if (szl>mx || szr>mx) continue; vector<pair<int, int>> dead; while ((int)child.size()>=2){ if ((int)child.size()&1){ dead.push_back(child.back()); child.pop_back(); } vector<pair<int, int>> new_child; for (int i=0; i<(int)child.size(); i+=2){ int x=child[i].first, y=child[i+1].first; if ((d1[x]+d1[y]-ii.first*2-GetDistance(x, y))){ new_child.emplace_back(x, child[i].second+child[i+1].second); }else{ dead.push_back(child[i]); dead.push_back(child[i+1]); } } new_child.swap(child); } if (child.size()){ int x=child[0].first, sz=child[0].second; for (auto &i:dead) if ((d1[x]+d1[i.first]-ii.first*2-GetDistance(x, i.first))) sz+=i.second; if (sz<=mx) return ans; }else return ans; } return -ans; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:63:31: warning: unused variable 'dr' [-Wunused-variable]
   63 |          int dl=d1[i]-common, dr=d2[i]-common;
      |                               ^~
#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...