Submission #31016

#TimeUsernameProblemLanguageResultExecution timeMemory
31016kajebiiiTowns (IOI15_towns)C++14
35 / 100
33 ms2076 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) #define ALL(v) (v).begin(),(v).end() #define one first #define two second typedef long long ll; typedef unsigned long long ull; typedef pair<double, double> pd; typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef pair<ll, pi> plp; typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli; const int INF = 0x3f2f1f0f; const ll LINF = 1ll * INF * INF * 2; map<pi, int> Mp; int getD(int i, int j) { if(Mp.count(pi(i, j)) == 0) Mp[pi(i, j)] = Mp[pi(j, i)] = getDistance(i, j); return Mp[pi(i, j)]; } int N, Sub; int hubDistance(int n, int sub) { Mp.clear(); N = n; Sub = sub; int max0D = -1, f = -1; for(int i=0; i<N; i++) { if(i == 0) continue; int d = getD(0, i); if(max0D < d) max0D = d, f = i; } int maxfD = -1, s = -1; for(int i=0; i<N; i++) { if(i == f) continue; int d = getD(f, i); if(maxfD < d) maxfD = d, s = i; } int R = INF; /* int from0 = (getD(0, f) + getD(0, s) - getD(s, f)) / 2; for(int i=0; i<N; i++) { int dis = (getD(0, i) + getD(0, f) - getD(i, f)) / 2; if(dis >= from0) { dis = max0D - dis; R = min(R, max(dis, maxfD - dis)); } } */ for(int i=0; i<N; i++) { int dis = (getD(f, i) - getD(i, s) + getD(s, f)) / 2; R = min(R, max(dis, getD(s, f) - dis)); } vector<pi> val; for(int i=0; i<N; i++) { int dis = (getD(f, i) - getD(i, s) + getD(s, f)) / 2; val.push_back(pi(dis, i)); } sort(ALL(val)); for(int i=0, j=0; i<N; i=j) { while(j < N && val[i].one == val[j].one) j++; int dis = val[i].one; // printf("[%d %d]\n", i, j); if(R == max(dis, getD(s, f) - dis)) { if(j - i <= (N/2) && i <= (N/2) && (N-j) <= (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...