Submission #105192

# Submission time Handle Problem Language Result Execution time Memory
105192 2019-04-10T23:38:29 Z CaroLinda Towns (IOI15_towns) C++14
35 / 100
36 ms 512 KB
#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 d[MAXN][MAXN] ;
//
void query( int x )
{ lp(i,0,N) d[x][i] = getDistance(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 ;
}

//union-find stuff
int pai[MAXN]  , h[MAXN];

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()
{
	int v[] = {0,0,0} ;
	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) pai[i] = i ;
		
	
	lp(i,0,N)
		lp(j,0,N)
		{
			if(i == j) continue ;
			if( d[j][i] != 0 ) d[i][j] = d[j][i] ;
			else d[i][j] = getDistance(i , j) ;
		}
	
	lp(i,0,tam)	
		lp(j,0,tam)
		{
			int x = good_vector[i] , y = good_vector[j] ;
			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 ;
	return R ;
}

int hubDistance( int n , int sub)
{
	N = n ;
	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

towns.cpp: In function 'int findMax(int)':
towns.cpp:24: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:81: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:118:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 15 ms 384 KB Output is correct
2 Correct 16 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 20 ms 512 KB Output is correct
5 Correct 36 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 16 ms 384 KB Output is correct
3 Correct 22 ms 384 KB Output is correct
4 Correct 18 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -