Submission #400275

#TimeUsernameProblemLanguageResultExecution timeMemory
400275biggTowns (IOI15_towns)C++14
Compilation error
0 ms0 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 115; const int INF = 1e6; int dista[MAXN][MAXN]; pair<int, int> p1, p2; map<int, int > AB; map<int, vector<int> > AB2; int get(int a, int b){ if(dista[a][b] != -1) return dista[a][b]; dista[a][b] = dista[b][a] = getDistance(a,b); return dista[a][b]; } int disttosv[MAXN]; int pai[MAXN], peso[MAXN]; int find(int x){ if(pai[x] == x) return x; return pai[x] = find(pai[x]); } void join(int u, int v){ u = find(u), v = find(v); if(u == v) return; if(peso[u] < peso[v]) swap(u,v); pai[v] = u; peso[u] += peso[v]; } int hubDistance(int N, int sub) { p1 = {0,0}; p2 = {0,0}; AB.clear(); AB2.clear(); memset(dista, -1, sizeof(dista)); memset(disttosv, 0, sizeof(disttosv)); for(int i = 0; i < N; i++) pai[i] = i, peso[i] = 1, distta[i][i] = 0; for(int i = 0; i < N; i++){ int d = get(0, i); if(d > p1.second) p1 = {i,d}; } for(int i = 0; i < N; i++){ int d = get(i, p1.first); if(d > p2.second) p2 = { i, d}; } int ans = INF; int diam = get(p1.first, p2.first); for(int i = 0; i < N; i++) ans = min(ans, (diam + abs(get(p1.first, i) - get(p2.first, i)))/2); if(sub <= 2) return ans; for(int i = 0; i < N; i++){ if(i == p1.first || i == p2.first) continue; int i1 = get(i, p1.first), i2 = get(i, p2.first); AB[i1 - (i1+i2-diam)/2]++; AB2[i1- (i1+i2-diam)/2].push_back(i); disttosv[i] = (i1+i2-diam)/2; } bool iscentroid = 0; if(sub == 4){ int jacontei = 1; for(map<int,int> :: iterator it = AB.begin(); it != AB.end(); it++){ if(it->first == ans || it->first == diam - ans){ if(jacontei <= N/2 && N - jacontei - it->second <= N/2 && it->second <= N/2) iscentroid = 1; } jacontei += it->second; } if(!iscentroid) ans = -ans; return ans; } int jacontei= 1; for(auto it : AB2){ if(it.first != ans && it.first != diam - ans){ jacontei += it.second.size(); continue; } if(jacontei <= (N/2) && N - jacontei - it.second.size() <= N/2) iscentroid = 1; for(int i = 0; i < it.second.size(); i++){ for(int j = i + 1; j < it.second.size(); j++){ if(get(it.second[i], it.second[j]) != disttosv[it.second[i]] + disttosv[it.second[j]]) join(it.second[i], it.second[j]); } } for(int i = 0; i < it.second.size(); i++) iscentroid &= (peso[find(it.second[i])] <= N/2); if(iscentroid) return ans; jacontei += it.second.size(); } if(!iscentroid) ans = -ans; return ans; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:42:54: error: 'distta' was not declared in this scope; did you mean 'dista'?
   42 |  for(int i = 0; i < N; i++) pai[i] = i, peso[i] = 1, distta[i][i] = 0;
      |                                                      ^~~~~~
      |                                                      dista
towns.cpp:84:31: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   84 |    jacontei += it.second.size();
      |                               ^
towns.cpp:87:59: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |   if(jacontei <= (N/2) && N - jacontei - it.second.size() <= N/2) iscentroid = 1;
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for(int i = 0; i < it.second.size(); i++){
      |                  ~~^~~~~~~~~~~~~~~~~~
towns.cpp:89:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |    for(int j = i + 1; j < it.second.size(); j++){
      |                       ~~^~~~~~~~~~~~~~~~~~
towns.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for(int i = 0; i < it.second.size(); i++) iscentroid &= (peso[find(it.second[i])] <= N/2);
      |                  ~~^~~~~~~~~~~~~~~~~~
towns.cpp:96:30: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   96 |   jacontei += it.second.size();
      |                              ^