Submission #169751

#TimeUsernameProblemLanguageResultExecution timeMemory
169751CaroLindaTowns (IOI15_towns)C++14
25 / 100
21 ms504 KiB
#include <bits/stdc++.h> #include "towns.h" #define debug printf #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define ff first #define ss second #define pb push_back #define mk make_pair #define ll long long #define sz size() #define pii pair<int,int> #define all(x) x.begin(),x.end() #define tiii tuple<int,int,int> #define mkt make_tuple const int MAXN = 120 , inf = 1e9+10 ; using namespace std ; int n , v , s , t , r ; int myRadio[MAXN] , pai[MAXN] ; int d[MAXN][MAXN] ; stack<int> List, bucket ; vector<int> comp[MAXN] ; inline void ask(int i , int j) { if( d[i][j] == -1 ) d[i][j] = d[j][i] = getDistance(i,j) ; } bool isDiff(int i, int j) { if( myRadio[i] < r && myRadio[j] < r ) return false ; else if( myRadio[i] > r && myRadio[j] > r ) return false ; if( !(myRadio[i] == myRadio[j] && myRadio[i] == r) ) return true ; ask(i,j) ; return d[s][i] + d[s][j] - d[i][j] == 2*r; } void print(stack<int> a , stack<int> b ) { debug("Printing stacks\n") ; while(!a.empty()) debug("%d " , a.top() ) , a.pop() ; debug("\n") ; while(!b.empty()) debug("%d " , b.top() ) , b.pop() ; debug("\n\n") ; } int find(int x) { if( x == pai[x] ) return x ; return pai[x] = find(pai[x]); } void join(int a, int b) { a = find(a) ; b=find(b) ; if(a == b) return ; if( comp[a].sz < comp[b].sz ) swap( a ,b ) ; for(int i : comp[b]) comp[a].pb(i) ; comp[b].clear() ; pai[b] = a ; } int hubDistance(int N, int sub) { memset(d, -1, sizeof d ) ; lp(i,0,N) d[i][i] =0 ; n = N ; lp(i,0,n) ask(0,i) ; v = 0 ; s = max_element( d[v] , d[v]+n ) - d[v] ; lp(i,0,n) ask(s,i) ; t = max_element( d[s] , d[s] + n ) - d[s] ; r = inf ; lp(i,0,n) { myRadio[i] = ( d[v][s] + d[s][i] - d[v][i] ) >> 1 ; r = min(r, max( myRadio[i] , d[s][t] - myRadio[i] ) ) ; } int toLeftS=0 , toRightS=0 , toLeftT=0 , toRightT=0 ; vector<int> auxS , auxT , toTest ; lp(i,0,n) { if( myRadio[i] < r ) toLeftS ++ ; else if( myRadio[i] > r ) toRightS ++ ; else toTest.pb(i) ; int aux = d[s][t] - myRadio[i] ; if( aux < r ) toRightT ++ ; else if( aux > r ) toLeftT ++ ; else auxT.pb(i) ; } toLeftS = max(toLeftS, toRightS ) ; toLeftT = max(toLeftT, toRightT ) ; if( sub <= 2 ) return r ; if( toLeftS > n/2 ) { if( toLeftT > n/2 ) return -r ; r = d[s][t] - r ; swap(toTest, auxT ) ; } lp(i,0,n) { pai[i] = i ; comp[i].pb(i) ; } lp(i,0,n) lp(j,i+1,n) if( !isDiff(i,j) ) join(i,j) ; int mx = -1 ; lp(i,0,n) mx = max( mx, (int)(comp[find(i)].sz) ) ; if( mx > n/2 ) return -r ; return r ; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:85:35: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
  s = max_element( d[v] , d[v]+n ) - d[v] ;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:88:37: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
  t = max_element( d[s] , d[s] + n ) - d[s] ;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
#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...