제출 #1220755

#제출 시각아이디문제언어결과실행 시간메모리
1220755HappyCapybara도시들 (IOI15_towns)C++20
26 / 100
36 ms584 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; map<pair<int,int>,int> res; int getDist(int a, int b){ if (a == b) return 0; if (a > b) swap(a, b); if (res.find({a, b}) == res.end()) res[{a, b}] = getDistance(a, b); return res[{a, b}]; } int hubDistance(int N, int sub){ res.clear(); vector<int> d1(N, 0), d2(N, 0); int bsf = 0, f1, f2; for (int i=1; i<N; i++){ int d = getDist(0, i); if (d > bsf){ bsf = d; f1 = i; } } bsf = 0; for (int i=0; i<N; i++){ if (i == f1) continue; int d = getDist(f1, i); d1[i] = d; if (d > bsf){ bsf = d; f2 = i; } } int R = pow(10, 9); map<int,vector<int>> m; for (int i=0; i<N; i++){ if (i == f1 || i == f2) continue; int d = getDist(f2, i); d2[i] = d; int l = (d1[i]+d2[i]-bsf)/2; R = min(R, max(d1[i], d2[i])-l); m[d1[i]-l].push_back(i); } bool bal = false; for (auto it=m.begin(); it != m.end(); it++){ if (it->first == R || it->first == bsf-R){ int x1 = 1, x2 = 0, x3 = 1; for (auto jt=m.begin(); jt != it; jt++) x1 += jt->second.size(); for (auto jt=next(it); jt != m.end(); jt++) x3 += jt->second.size(); for (int v : it->second){ int cur = 0; for (int w : it->second){ if (d1[v]+d1[w]-getDist(v, w) > 2*it->first) cur++; } x2 = max(x2, cur); } /*set<pair<int,int>> s, d; for (int v : it->second) s.insert({1, v}); while (s.size() > 1){ if (s.size() % 2){ d.insert(*s.begin()); s.erase(s.begin()); } set<pair<int,int>> ns; while (!s.empty()){ auto g1 = s.begin(), g2 = next(s.begin()); if (d1[g1->second]+d1[g2->second]-getDist(g1->second, g2->second) > 2*it->first) ns.insert({g1->first+g2->first, g1->second}); else { d.insert(*g1); d.insert(*g2); } s.erase(s.begin()); s.erase(s.begin()); } s = ns; } if (!s.empty()){ x2 = s.begin()->first; for (auto [num, rep] : d){ if (d1[s.begin()->second]+d1[rep]-getDist(s.begin()->second, rep) > 2*it->first) x2 += num; } }*/ //cout << x1 << " " << x2 << " " << x3 << endl; if (x1 <= N/2 && x2 <= N/2 && x3 <= N/2) bal = true; } } if (bal) return R; else return -R; }
#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...