제출 #105462

#제출 시각아이디문제언어결과실행 시간메모리
105462CaroLinda도시들 (IOI15_towns)C++14
51 / 100
30 ms1016 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 ; int perp[MAXN] ; int d[MAXN][MAXN] ; bool marc[MAXN][MAXN] ; map<int, vector<int> > g ; // void init() { memset( d , 0 , sizeof d ) ; memset(marc , 0 , sizeof marc ) ; lp(i,0,MAXN) marc[i][i] = 1 ; R = inf ; g.clear() ; } void ask( int x , int y ) { if( marc[x][y] ) return ; d[x][y] = d[y][x] = getDistance(x,y) ; marc[x][y] = marc[y][x] = 1 ; } bool check( vector<int> &v ) { if(v.size() <= N/2) return 1; int candidat = v[0]; int cnt = 0; for(auto it : v){ ask(it , candidat) ; if(d[it][candidat] == perp[it] + perp[candidat]) { if(!cnt) candidat = it, cnt = 1; else --cnt; } else ++cnt; } cnt = v.size(); for(auto it : v){ ask(it , candidat) ; if(d[candidat][it] == perp[candidat] + perp[it]) --cnt; } return (cnt <= N/2); } int hubDistance( int n , int sub) { N = n ; vector<int> s ; int balanced = 0 ; init() ; lp(i,0,n) ask(0,i) ; A = max_element( d[0] , d[0]+n )- d[0] ; lp(i,0,N) ask(A , i) ; B = max_element( d[A] , d[A] + n ) - d[A] ; lp(i,0,N) ask(B , i) ; lp(i,0,n) perp[i] = ( d[A][i] + d[B][i] - d[A][B] ) / 2 ; lp(i,0,n) R = min( R , max( d[A][i] , d[B][i] ) - perp[i] ) ; if( sub < 3 ) return R ; for(int i=0; i<n; ++i) { int L = d[A][i] - perp[i] ; g[L].pb(i); } int cnt1 = 0, cnt2 = n; for(auto &it : g) { cnt2 -= it.second.size(); if(max(it.first, d[A][B] - it.first) == R && cnt1 <= n/2 && cnt2 <= n/2) balanced |= check(it.second); cnt1 += it.second.size(); } return R * ( balanced ? 1 : -1 ) ; }

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

towns.cpp: In function 'bool check(std::vector<int>&)':
towns.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(v.size() <= N/2) return 1;
        ~~~~~~~~~^~~~~~
towns.cpp:56:17: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     cnt = v.size();
           ~~~~~~^~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:73:35: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
   A = max_element( d[0] , d[0]+n )- d[0] ;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:75:38: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
   B = max_element( d[A] , d[A] + n ) - d[A] ;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:93:32: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
         cnt2 -= it.second.size();
                                ^
towns.cpp:98:32: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
         cnt1 += it.second.size();
                                ^
#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...