Submission #432775

#TimeUsernameProblemLanguageResultExecution timeMemory
432775balbit도시들 (IOI15_towns)C++14
13 / 100
51 ms624 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define f first #define s second #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do( T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);} #else #define bug(...) #endif // BALBIT #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int )((x).size()) #define pb push_back #define REP(i,n) for (int i = 0; i<n; ++i) #define REP1(i,n) for (int i = 1; i<=n; ++i) #define MX(a,b) a = max(a,b) #define MN(a,b) a = min(a,b) map<pii, int> mp; int getd(int a, int b){ if (a==b) return 0; if (a>b) swap(a,b); if (!mp.count({a,b})) mp[{a,b}] = getDistance(a,b); return mp[{a,b}]; } int hubDistance(int n, int sub) { mp.clear(); int p1=-1, p2=-1; vector<int> C(n); { int far = 0; REP(i,n) { if (i != 0) { C[i] = getd(0,i); if (getd(0,i) > far) { far = getd(0,i); p1 = i; } } } } vector<int> A(n); vector<int> B(n); { int far = 0; REP(i,n) { if (i!=p1) { A[i] = getd(p1, i); if (getd(p1,i) > far) { far = getd(p1,i); p2 = i; } } } } assert(p1 != -1 && p2 != -1); bug(p1, p2); int dia = A[p2]; int P = (C[p1] + C[p2] - dia) / 2; int R = 2000000000; bug(P); int L = C[p1] - P; map<int, vector<pii> > under; // int cent = -1; // int ncent = -1; REP(i,n) { // B[i] = getd(p2,i); if (A[i] - C[i] == L-P) { bug("hI",i); under[C[p1] - P].pb({i,A[i] - L}); // bug(C[i] - P); continue; // just pretend it's under that } B[i] = C[p2] + C[i] - P - P; int pp = (A[i] + B[i] - dia) / 2; bug (i, A[i]-pp, pp); under[A[i] - pp].pb({i,pp}); } int who = -1; int nstuff = 0; for (auto &ele : under) { int hi = max(ele.f, dia-ele.f); // assert(hi % 2 == 0); if (hi < R) { R = hi; } if (hi == R) { if (nstuff <= n/2 && (n - nstuff - SZ(ele.s)) <= n/2) { who = ele.f; } } nstuff += SZ(ele.s); } bug(dia, R); bug(who); for (pii x : under[who]) { bug(x.f, x.s); } if (who == -1) return -R; if (SZ(under[who]) <= n/2) return R; bug(who); vector<pii> fren = under[who]; REP(i, SZ(fren)) { int nfr = 0; REP(j,i) { if (getd(fren[i].f, fren[j].f) < fren[i].s + fren[j].s) { ++nfr; if (nfr > n/2) return -R; } } } return R; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:117:14: warning: variable 'x' set but not used [-Wunused-but-set-variable]
  117 |     for (pii x : under[who]) {
      |              ^
towns.cpp:40:28: warning: unused parameter 'sub' [-Wunused-parameter]
   40 | 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...