# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105210 |
2019-04-11T01:56:55 Z |
CaroLinda |
Towns (IOI15_towns) |
C++14 |
|
27 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 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 ) ;
}
void query( int x )
{
lp(i,0,N) {
d[x][i] = d[i][x] = getDistance(x,i) ;
marc[x][i] = marc[i][x] = 1 ;
}
}
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)
if(!marc[i][j])
{
d[i][j] = d[j][i] = getDistance(i,j) ;
marc[i][j] = marc[j][i] = 1 ;
}
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
towns.cpp: In function 'int findMax(int)':
towns.cpp:43: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:96: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:135:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
512 KB |
Output is correct |
2 |
Correct |
15 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
25 ms |
384 KB |
Output is correct |
5 |
Correct |
27 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
512 KB |
Output is correct |
2 |
Correct |
27 ms |
384 KB |
Output is correct |
3 |
Correct |
19 ms |
384 KB |
Output is correct |
4 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |