Submission #677140

#TimeUsernameProblemLanguageResultExecution timeMemory
677140jamezzzTowns (IOI15_towns)C++17
25 / 100
18 ms556 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pf printf #define pb push_back #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() typedef vector<int> vi; typedef pair<int,int> ii; int cnt,n; map<int,int> memo[150]; inline int ask(int a,int b){ if(a==b)return 0; if(memo[a].find(b)!=memo[a].end())return memo[a][b]; ++cnt; assert(cnt<7*n/2); return memo[a][b]=memo[b][a]=getDistance(a,b); } int hubDistance(int N,int sub){ n=N; cnt=0; for(int i=0;i<N;++i)memo[i].clear(); int a=0,b=0,diam=0; for(int i=0;i<N;++i)if(ask(a,i)>ask(a,b))b=i; for(int i=0;i<N;++i)diam=max(diam,ask(b,i)); int ans=diam; vector<ii> v; for(int i=0;i<N;++i){ int ab=ask(a,b),ai=ask(a,i),bi=ask(i,b); int db=(ab+bi-ai)/2; v.pb({db,i}); ans=min(ans,max(db,diam-db)); } sort(all(v)); for(int i=0;i<N;++i){ if(max(v[i].fi,ask(a,b)-v[i].fi)!=ans)continue; int l=i,r=i; while(r<N-1&&v[r].fi==v[r+1].fi)++r; if(l>N/2||N-r>N/2)continue; vector<vi> cur,nxt,dead; for(int i=l;i<=r;++i)cur.pb({v[i].se}); //pf("l: %d, r: %d\n",l,r); vi rep={}; while(!cur.empty()){ /* pf("cur: "); for(vi x:cur){ pf("{"); for(int i:x)pf("%d ",i); pf("} "); } pf("\n"); */ for(int i=0;i<sz(cur);i+=2){ if(i+1==sz(cur)){ rep=cur[i]; } else{ int x=cur[i][0],y=cur[i+1][0]; if(ask(b,x)+ask(b,y)-ask(x,y)>2*v[l].fi){ vi tmp; for(int x:cur[i])tmp.pb(x); for(int x:cur[i+1])tmp.pb(x); nxt.pb(tmp); } else dead.pb(cur[i]),dead.pb(cur[i+1]); } } swap(cur,nxt); nxt.clear(); } if(rep.empty())return ans; int num=rep.size(); for(vi i:dead){ int x=rep[0],y=i[0]; if(ask(b,x)+ask(b,y)-ask(x,y)>2*v[l].fi)num+=i.size(); } if(num<=N/2)return ans; i=r; } return -ans; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:53:11: warning: declaration of 'i' shadows a previous local [-Wshadow]
   53 |   for(int i=l;i<=r;++i)cur.pb({v[i].se});
      |           ^
towns.cpp:46:10: note: shadowed declaration is here
   46 |  for(int i=0;i<N;++i){
      |          ^
towns.cpp:68:12: warning: declaration of 'i' shadows a previous local [-Wshadow]
   68 |    for(int i=0;i<sz(cur);i+=2){
      |            ^
towns.cpp:46:10: note: shadowed declaration is here
   46 |  for(int i=0;i<N;++i){
      |          ^
towns.cpp:76:15: warning: declaration of 'x' shadows a previous local [-Wshadow]
   76 |       for(int x:cur[i])tmp.pb(x);
      |               ^
towns.cpp:73:10: note: shadowed declaration is here
   73 |      int x=cur[i][0],y=cur[i+1][0];
      |          ^
towns.cpp:77:15: warning: declaration of 'x' shadows a previous local [-Wshadow]
   77 |       for(int x:cur[i+1])tmp.pb(x);
      |               ^
towns.cpp:73:10: note: shadowed declaration is here
   73 |      int x=cur[i][0],y=cur[i+1][0];
      |          ^
towns.cpp:89:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   89 |   int num=rep.size();
      |           ~~~~~~~~^~
towns.cpp:90:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
   90 |   for(vi i:dead){
      |          ^
towns.cpp:46:10: note: shadowed declaration is here
   46 |  for(int i=0;i<N;++i){
      |          ^
towns.cpp:92:56: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   92 |    if(ask(b,x)+ask(b,y)-ask(x,y)>2*v[l].fi)num+=i.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...