Submission #670066

#TimeUsernameProblemLanguageResultExecution timeMemory
670066alvingogoTowns (IOI15_towns)C++14
100 / 100
20 ms384 KiB
#include <bits/stdc++.h> #include <towns.h> #pragma GCC optimize("Ofast") #define AquA cin.tie(0);ios_base::sync_with_stdio(0); #define fs first #define sc second #define p_q priority_queue using namespace std; map<pair<int,int>,int> mp; int qt=0; int f(int x,int y){ if(x==y){ return 0; } if(x>y){ swap(x,y); } if(mp.find({x,y})!=mp.end()){ return mp[{x,y}]; } qt++; return mp[{x,y}]=getDistance(x,y); } int hubDistance(int n,int sub){ qt=0; mp.clear(); int a=0; for(int i=0;i<n;i++){ if(f(0,i)>f(0,a)){ a=i; } } int b=a; for(int i=0;i<n;i++){ if(f(a,i)>f(a,b)){ b=i; } } assert(a!=b); map<int,pair<int,vector<int> > > m; int dd=(f(0,a)-f(0,b)+f(a,b))/2; for(int i=0;i<n;i++){ if(i!=a){ int x=min(dd,(f(a,i)-f(0,i)+f(a,0))/2); m[x].fs=max(m[x].fs,f(i,a)-x); m[x].sc.push_back(i); } } vector<int> g; int cz=0; for(auto &h:m){ g.push_back(h.fs); cz++; } int p=g.size(); vector<int> dis(p,0); for(int i=0;i<p;i++){ dis[i]=max(dis[i],max(g[i],f(a,b)-g[i])); dis[i]=max(dis[i],m[g[i]].fs); for(int j=i+1;j<p;j++){ int u=g[j]-g[i]; dis[i]=max(dis[i],m[g[j]].fs+u); dis[j]=max(dis[j],m[g[i]].fs+u); } } int ans=2e9; for(int i=0;i<p;i++){ ans=min(ans,dis[i]); } int at=-1; auto cal=[&](int y){ vector<int> dis2(n); for(int i=0;i<n;i++){ int x=min(dd,(f(a,i)-f(0,i)+f(a,0))/2); dis2[i]=f(a,i)-x+abs(g[y]-x); } vector<int> vis(n),pp(n); int cnt=0,lo=0; for(int i=0;i<n;i++){ if(cnt==0){ lo=i; cnt++; } else{ if(f(lo,i)!=dis2[i]+dis2[lo]){ cnt++; vis[i]=1; pp[lo]++; } else{ cnt--; } } } int cc=0; for(int i=0;i<n;i++){ if(!vis[i]){ int q=(f(lo,i)!=dis2[i]+dis2[lo]); if(q){ cc+=pp[i]+1; } } } if(cc<=n/2){ at=1; } }; int nw=1; int rr=0; for(int i=0;i<p;i++){ int c=m[g[i]].sc.size(); int u=n-c-nw; if(nw<=n/2 && u<=n/2 && dis[i]==ans){ if(c<=n/2){ at=1; continue; } rr++; cal(i); } nw+=c; } assert(rr<=1); assert(2*qt<=7*n); return ans*at; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:56:17: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   56 |     int p=g.size();
      |           ~~~~~~^~
towns.cpp:112:30: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  112 |         int c=m[g[i]].sc.size();
      |               ~~~~~~~~~~~~~~~^~
towns.cpp:25:27: warning: unused parameter 'sub' [-Wunused-parameter]
   25 | 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...