Submission #592260

#TimeUsernameProblemLanguageResultExecution timeMemory
592260DeepessonTowns (IOI15_towns)C++17
Compilation error
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; std::map<pii,int> memoria; int count=0; int smartgetDistance(int a, int b){ if(a==b)return 0; if(a>b)std::swap(a,b); pii x = {a,b}; if(memoria.find(x)!=memoria.end())return memoria[x]; int d = getDistance(a,b); memoria[x]=d; ++count; return d; } 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 = smartgetDistance(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) { count=0; memoria.clear(); 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 exp_a=0,exp_b=0; 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; dist_centro[i]=base; if(custo<ans){///Fora da sub de A ou B ans=custo; exp_a = a-base; exp_b = b-base; } } 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 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); }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; } assert(sub==3); assert(fora.size()==(N-(grupos[0]+grupos[1]))); std::vector<pii> opcoes; for(autox:fora){ bool ok=false; for(int i=0;i!=opcoes.size();++i){ int p = opcoes[i].first; if(smartgetDistance(p,x)<(dist_centro[x]+dist_centro[p])){ ++opcoes[i].second; assert(count<=((N*(N-1))/2)); assert(!ok); ok=true; } } if(!ok) opcoes.push_back({x,1}); safe:{} } assert(count<=((N*(N-1))/2)); for(auto&x:opcoes)if(x.second>lim)return -ans; return ans; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from towns.cpp:1:
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:85:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |  assert(fora.size()==(N-(grupos[0]+grupos[1])));
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
towns.cpp:87:11: error: found ':' in nested-name-specifier, expected '::'
   87 |  for(autox:fora){
      |           ^
      |           ::
towns.cpp:87:6: error: 'autox' has not been declared
   87 |  for(autox:fora){
      |      ^~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from towns.cpp:1:
towns.cpp:102:2: error: could not convert '((count <= ((N * (N - 1)) / 2)) ? (void)0 : __assert_fail(((const char*)"count<=((N*(N-1))/2)"), ((const char*)"towns.cpp"), 102, ((const char*)(& __PRETTY_FUNCTION__))))' from 'void' to 'bool'
  102 |  assert(count<=((N*(N-1))/2));
      |  ^~~~~~
      |  |
      |  void
towns.cpp:103:2: error: expected primary-expression before 'for'
  103 |  for(auto&x:opcoes)if(x.second>lim)return -ans;
      |  ^~~
towns.cpp:102:31: error: expected ')' before 'for'
  102 |  assert(count<=((N*(N-1))/2));
      |                               ^
      |                               )
  103 |  for(auto&x:opcoes)if(x.second>lim)return -ans;
      |  ~~~                           
towns.cpp:87:5: note: to match this '('
   87 |  for(autox:fora){
      |     ^