Submission #31020

#TimeUsernameProblemLanguageResultExecution timeMemory
31020kajebiiiTowns (IOI15_towns)C++14
100 / 100
29 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 max0D, f, maxfD, s; bool isDiff(int a, int b, int dis) { // return a != b; return (getD(f, a) + getD(f, b) - 2 * dis) == getD(a, b); } bool haveMajor(int dis, vector<int> candi) { if(SZ(candi) == 0) return false; vector<int> minor; vector<pi> rep; int nowX = -1, nowL = 0, maxL = 0; for(int x : candi) { if(nowX == -1) { nowX = x; nowL = maxL = 1; }else{ if(!isDiff(nowX, x, dis)) nowL++, maxL++; else{ nowL--; minor.push_back(x); if(nowL == 0) { rep.push_back(pi(nowX, maxL)); nowX = -1; } } } } if(nowX != -1) rep.push_back(pi(nowX, maxL)); // for(pi e : rep) printf("[%d %d] ", e.one, e.two); puts(""); for(int x : minor) printf("%d ", x); puts(""); int mj = rep.back().one, cnt = 0; for(pi e : rep) if(!isDiff(mj, e.one, dis)) cnt += e.two; for(int x : minor) if(!isDiff(mj, x, dis)) cnt++; // return cnt > SZ(candi) / 2; return cnt > N/2; } int hubDistance(int n, int sub) { Mp.clear(); N = n; Sub = sub; 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; } 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; vector<pi> list; for(int i=0; i<N; i++) { int dis = (getD(0, i) + getD(0, f) - getD(i, f)) / 2; int r = -1; if(dis >= from0) { r = max0D - dis; R = min(R, max(r, maxfD - r)); }else{ r = max0D - from0; } list.push_back(pi(r, i)); } sort(ALL(list)); int lim = N/2; // printf("f %d | s %d\n", f, s); for(pi &e : list) printf("[%d %d] ", e.one, e.two); for(int i=0, j=0; i<N; i=j) { vector<int> candi; int r = list[i].one; while(j<N && list[i].one == list[j].one) candi.push_back(list[j++].two); if(R == max(r, maxfD - r)) { if(i <= lim && N-j <= lim && j-i <= lim) return R; if(i <= lim && N-j <= lim && j-i > lim) if(!haveMajor(r, candi)) 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...