Submission #1216730

#TimeUsernameProblemLanguageResultExecution timeMemory
1216730JooDdaeTowns (IOI15_towns)C++20
0 / 100
21 ms8184 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; int hubDistance(int N, int sub) { vector<vector<int>> D(N, vector<int>(N, 0)); for(int i=1;i<N;i++) D[0][i] = D[i][0] = getDistance(0, i); int E = max_element(D[0].begin(), D[0].end()) - D[0].begin(); for(int i=0;i<N;i++) if(i != E) D[E][i] = D[i][E] = getDistance(E, i); int X = max_element(D[E].begin(), D[E].end()) - D[E].begin(); vector<int> C(N, 0), mp(1001001, 0); for(int i=0;i<N;i++) mp[C[i] = (D[E][i]+D[0][E] - D[0][i])/2]++; int R = 1e9, h1 = -1, h2 = -1; for(int i=0;i<N;i++) if(i != E && C[i] <= C[X]) { auto r = max(C[i], D[E][X]-C[i]); if(R > r) R = r, h1 = i, h2 = -1; else if(R == r && C[h1] != C[i]) h2 = i; } vector<int> c(2, 0); for(int i=0;i<N;i++) c[C[i] > C[h1]]++; if(h2 != -1) { if(max(c[0], c[1]) <= N/2) return R; if(c[0] <= N/2) h1 = h2, c[0] += mp[C[h2]], c[1] -= mp[C[h2]]; } c[0] -= mp[C[h1]]; if(max(c[0], c[1]) > N/2) return -R; vector<int> v; for(int i=0;i<N;i++) if(C[i] == C[h1]) v.push_back(i); vector<vector<int>> same(N, vector<int>(N, -1)); auto check = [&](int x, int y) { if(x == y) return 1; if(same[x][y] != -1) return same[x][y]; D[x][y] = D[y][x] = getDistance(x, y); return same[y][x] = same[x][y] = D[E][x] + D[E][y] != D[x][y] + C[h1]*2; }; int c1 = 0, c2 = 0; // vector<int> S; // vector<vector<int>> L; // for(auto x : v) { // S.push_back(x); // if(check(S[0], x)) c1++; // else if(++c2 == c1) L.push_back(S), S.clear(), c1 = c2 = 0; // } // cout << E << " " << h1 << "\n"; // for(auto x : v) { // for(auto y : v) { // cout << x << " " << y << " " << check(x, y) << '\n'; // cout << " " << D[E][x] << " " << D[E][y] << " " << D[x][y] << " " << C[h1] << "\n"; // } // } // for(auto V : L) { // for(auto x : V) { // if(check(S[0], V[0])) c1 += check(V[0], x); // else if(!check(V[0], x)) c1 += check(S[0], x); // } // } // return c1 <= N/2 ? R : -R; for(auto S : v) { c1 = 0; for(auto x : v) c1 += check(S, x); if(c1 > N/2) return -R; } 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...