Submission #1028397

#TimeUsernameProblemLanguageResultExecution timeMemory
1028397Dan4LifeTowns (IOI15_towns)C++17
25 / 100
10 ms1116 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; #define sz(a) (int)a.size() using ar2 = array<int,2>; const int mxN = 115; int n, mem[mxN][mxN]; map<int,int> M, cnt; int dis(int a, int b){ if(a==b) return 0; if(mem[a][b]!=-1) return mem[a][b]; if(mem[b][a]!=-1) return mem[b][a]; return mem[a][b]=mem[b][a]=getDistance(a,b); } int p[mxN], sz[mxN]; int findSet(int i) { return p[i]==i?i:p[i]=findSet(p[i]); } bool isSameSet(int i, int j) { return findSet(i)==findSet(j); } void unionSet(int i, int j){ int x = findSet(i), y = findSet(j); if(x==y) return; if(sz[x]<sz[y]) swap(x,y); p[y]=x; sz[x]+=sz[y]; } int a, b, diameter; bool same(int i, int j, int lpos){ int rpos = diameter-lpos; int i_u = dis(a,i)-lpos; if(dis(a,i)<dis(b,i)) i_u = dis(b,i)-rpos; int u_j = dis(a,j)-lpos; if(dis(a,j)<dis(b,j)) u_j = dis(b,j)-rpos; return i_u+u_j != dis(i,j); } int hubDistance(int N, int sub) { n = N; ar2 mx = {0,0}; M.clear(); cnt.clear(); memset(mem,-1,sizeof(mem)); for(int i = 0; i < n; i++) mx=max(mx,{dis(0,i),i}); a = mx[1]; mx = {0,0}; for(int i = 0; i < n; i++) mx=max(mx,{dis(a,i),i}); b = mx[1]; diameter = mx[0]; int ans = diameter; for(int i = 0; i < n; i++){ int i_0 = (dis(0,i)+dis(0,a)-dis(a,i))/2; int lpos = dis(0,a) - i_0; int rpos = diameter-lpos; M[i_0] = max(lpos, rpos); cnt[i_0]++; } for(auto u : M) ans=min(ans, u.second); if(sub<=2) return ans; int tot = 0; for(auto u : M){ int pos = u.first, mx_dis = u.second; tot+=cnt[pos]; if(mx_dis!=ans) continue; if(tot-cnt[pos] > n/2) continue; if(n-tot > n/2) continue; return ans; } return -ans; }
#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...