Submission #105329

#TimeUsernameProblemLanguageResultExecution timeMemory
105329CaroLindaTowns (IOI15_towns)C++14
Compilation error
0 ms0 KiB
#include "towns.h"
#include <bits/stdc++.h>
 
#define lp(i,a,b) for(int i = a ; i < b ; i++)
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define MAXN 120
 
const int inf = 1e9 + 5 ; 
 
using namespace std;
 
//
int N  , A , B  , R , man;
int perp[MAXN] ;
int v[] = {0,0,0} ;
int d[MAXN][MAXN] ;
bool marc[MAXN][MAXN] ;
//
 
//union-find stuff
int pai[MAXN]  , h[MAXN];
 
void init()
{
	memset( v , 0 , sizeof v  ) ;
	lp(i,0,N) pai[i] = i ;
	memset( h , 0 , sizeof h ) ;
  memset(marc , 0 , sizeof marc ) ;
  lp(i,0,N) marc[i][i] = 1 ;
}
 
int getDist( int x , int y )
{
  if( marc[x][y] ) return d[x][y] ;
  marc[x][y] = marc[y][x] = 1 ;
  d[x][y] = d[y][x] = getDistance( x , y ) ;
  return d[x][y] ;
}
 
void query( int x )
{
   lp(i,0,N) 
    d[x][i] = getDist( x, i ) ;
}
 
int findMax( int x )
{ return max_element(d[x] , d[x] + N) - d[x] ; }
 
int findPerpendicular( int x )
{ return (d[A][x] + d[B][x] - d[A][B])/2 ; }
 
int findRadio()
{
	int ans = inf ;
	lp(i,0,N)
	{
		int k = max( d[A][i] , d[B][i] ) - perp[i] ;
		int Man = d[A][i] > d[B][i] ? A : B ;
		if( k < ans ) ans = k , man = Man ;
	}
	return ans ;
}
 
int checkPosition( int x )
{
	int k = d[man][x] - perp[x] ;
	if( k < R ) return 0 ;
	if( k == R ) return 1 ;
	return 2 ;
}
 
int find(int x)
{
	if(pai[x] == x) return x ;
	return pai[x] = find( pai[x] ) ;
}
 
void join( int x, int y )
{
	x = find(x) ;
	y = find(y) ;
	if(x == y) return ;
	pai[y] = x;
}
 
int sub4()
{
	lp(i,0,N)
		v[ checkPosition(i) ] ++ ;
	lp(i,0,3)
		if( v[i] > N/2 ) return -R ;
	return R ;
}
 
int sub3()
{
	vector<int> good_vector ;
	lp(i,0,N)
		if( checkPosition(i) == 1 ) good_vector.pb(i) ;
	int tam = good_vector.size() ;
	
	lp(i,0,N)
		lp(j,0,N)
			d[i][j] = getDist( i , j ) ;
	
	lp(i,0,tam)	
		lp(j,0,tam)
		{
			int x = good_vector[i] , y = good_vector[j] ;
			if( x == y ) continue ;
			if( d[A][B] + d[x][y] != d[A][x] + d[B][y] ) join( x , y ) ;
		}
	lp(i,0,N) h[ find(i) ] ++ ;
	lp(i,0,N)
		if( h[i] > N/2 ) return - R ;
	sub4() ;
	if( v[0] > N/2 or v[2] > N/2 ) return -R ;
	return R ;
}
 
int hubDistance( int n , int sub)
{
	N = n ;
	init() ;
	query(0) ;
	A = findMax(0) ;
	query(A) ;
	B = findMax(A) ;
	query(B) ;
	lp(i,0,n) perp[i] = findPerpendicular(i) ;
	R = findRadio() ;
	if( sub < 3 ) return R ;
	if( sub == 3 ) return sub3() ;
	if( sub == 4 ) return sub4() ;
}

Compilation message (stderr)

towns.cpp:39:2: error: stray '\302' in program
   d[x][y] = d[y][x] = getDistance( x , y ) ;
  ^
towns.cpp:39:3: error: stray '\240' in program
   d[x][y] = d[y][x] = getDistance( x , y ) ;
   ^
towns.cpp:40:2: error: stray '\302' in program
   return d[x][y] ;
  ^
towns.cpp:40:3: error: stray '\240' in program
   return d[x][y] ;
   ^
towns.cpp: In function 'int findMax(int)':
towns.cpp:50:39: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
 { return max_element(d[x] , d[x] + N) - d[x] ; }
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp: In function 'int sub3()':
towns.cpp:103:28: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int tam = good_vector.size() ;
            ~~~~~~~~~~~~~~~~^~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:138:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^