제출 #592223

#제출 시각아이디문제언어결과실행 시간메모리
592223Deepesson도시들 (IOI15_towns)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define MAX 115 int getDistance(int i, int j); int hubDistance(int N, int sub); typedef std::pair<int,int> pii; int dist[MAX][2]; pii MaisDistante(int N,int x,int p){ int best=-1,alvo=0; for(int i=0;i!=N;++i){ if(i==x)continue; int d = getDistance(i,x); if(d>best){ best=d; alvo=i; } dist[i][p]=d; } return {best,alvo}; } int dist_centro[MAX]; ///Queries usadas: 3N-3 int hubDistance(int N, int sub) { pii alpha = MaisDistante(N,0,1); pii beta = MaisDistante(N,alpha.second,0); MaisDistante(N,beta.second,1); int d = beta.first; int ans=1e9; int eixo; int exp_a,exp_b; for(int i=0;i!=N;++i){ if(i==alpha.second||i==beta.second)continue; int a = dist[i][0]; int b = dist[i][1]; int soma = a+b; int subt = soma-d; int base = subt/2; int custo = std::max(a,b)-base; if(custo<ans){///Fora da sub de A ou B eixo=i; ans=custo; exp_a = a-base; exp_b = b-base; } } if(sub<=2) return ans; std::vector<int> fora; int grupos[2]={1,1}; for(int i=0;i!=N;++i){ if(i==alpha.second||i==beta.second)continue; int a = dist[i][0]; int b = dist[i][1]; int soma = a+b; int subt = soma-d; int base = subt/2; int custo = std::max(a,b)-base; int dist_a = a-base; int dist_b = b-base; if(dist_a == exp_a && dist_b == exp_b){///Fora da sub de A ou B fora.push_back(i); dist_centro[i]=base; }else {///Na subarvore de A ou B if(a>b)grupos[0]++;else grupos[1]++; } } int lim=N/2; if(grupos[0]>lim||grupos[1]>lim)return -ans; ///Para a sub 4 if(sub==4){ int sum = N-(grupos[0]+grupos[1]); if(sum>lim)return -ans; return ans; } std::vector<pii> opcoes; for(auto&x:base){ for(int i=0;i!=opcoes.size();++i){ int p = opcoes[i].first; if(getDistance(p,x)==dist_centro[x]+dist_centro[p]){ ++opcoes[i].second; if(opcoes[i].second>lim)return -ans; goto safe; } } opcoes.push_back({x,1}); safe:{} } return ans; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:56:13: warning: unused variable 'custo' [-Wunused-variable]
   56 |         int custo = std::max(a,b)-base;
      |             ^~~~~
towns.cpp:75:13: error: 'base' was not declared in this scope
   75 |  for(auto&x:base){
      |             ^~~~
towns.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int i=0;i!=opcoes.size();++i){
      |                     ~^~~~~~~~~~~~~~~
towns.cpp:84:31: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   84 |         opcoes.push_back({x,1});
      |                               ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from towns.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~