제출 #105197

#제출 시각아이디문제언어결과실행 시간메모리
105197CaroLinda도시들 (IOI15_towns)C++14
35 / 100
30 ms512 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] ; // 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() { memset( v , 0 , sizeof v ) ; 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( 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 ; 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() ; }

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int findMax(int)':
towns.cpp:25: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:82: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:121:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...