Submission #400236

#TimeUsernameProblemLanguageResultExecution timeMemory
400236peuchTowns (IOI15_towns)C++17
25 / 100
23 ms1132 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 310; int dist[MAXN][MAXN]; int marc[MAXN][MAXN]; int p1, p2, n; int cnt; int getD(int i, int j){ if(marc[i][j]) return dist[i][j]; marc[i][j] = marc[j][i] = 1; if(i == j) return dist[i][j] = dist[j][i] = 0; cnt++; return dist[i][j] = dist[j][i] = getDistance(i, j); } int getSize(vector<int> values, int goal){ vector<set<int> > alive, dead; for(int i = 0; i < values.size(); i++){ set<int> aux; aux.insert(values[i]); alive.push_back(aux); } while(alive.size() > 1){ if(alive.size() % 2 == 1) alive.pop_back(); vector<set<int> > aux; for(int i = 0; i < alive.size(); i += 2){ set<int> g1, g2; g1 = alive[i]; g2 = alive[i + 1]; int v1 = *g1.begin(), v2 = *g2.begin(); int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2; if(x != goal){ while(!g2.empty()){ g1.insert(*g2.begin()); g2.erase(*g2.begin()); } aux.push_back(g1); } else{ dead.push_back(g1); dead.push_back(g2); } } alive = aux; } if(alive.empty()) return 1; for(int i = 0; i < dead.size(); i++){ set<int> g1, g2; g1 = alive[0]; g2 = dead[i]; int v1 = *g1.begin(), v2 = *g2.begin(); int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2; if(x != goal){ while(!g2.empty()){ g1.insert(*g2.begin()); g2.erase(*g2.begin()); } } alive[0] = g1; } return (alive[0].size() > n / 2) ? -1 : 1; } int hubDistance(int N, int sub) { srand(time(0)); n = N; p1 = 0, p2 = 0; int maxi = 0; cnt = 0; memset(dist, 0, sizeof(dist)); memset(marc, 0, sizeof(marc)); for(int i = 0; i < N; i++){ int aux = getD(0, i); if(aux > maxi) p1 = i, maxi = aux; } maxi = 0; for(int i = 0; i < N; i++) if(getD(p1, i) > maxi) maxi = getD(p1, i), p2 = i; int diam = getD(p1, p2); int cruz0 = (diam + getD(p1, 0) - getD(p2, 0)) / 2; int ans = max(cruz0, diam - cruz0); for(int i = 0; i < N; i++){ int x = (getD(p1, 0) + getD(p1, i) - getD(0, i)) / 2; ans = min(ans, max(x, diam - x)); } if(sub <= 2) return ans; int lSize = 0, rSize = 0; vector<int> lMid, rMid; for(int i = 0; i < N; i++){ int x = (getD(p1, 0) + getD(p1, i) - getD(0, i)) / 2; if(x < min(ans, diam - ans)) lSize++; else if(x == min(ans, diam - ans)) lMid.push_back(i); else if(x == max(ans, diam - ans)) rMid.push_back(i); else rSize++; } if(lSize > N / 2 || rSize > N / 2) return -ans; else if(lMid.size() > N / 2) return getSize(lMid, min(ans, diam - ans)) * ans; else if(rMid.size() > N / 2) return getSize(rMid, max(ans, diam - ans)) * ans; return ans; }

Compilation message (stderr)

towns.cpp: In function 'int getSize(std::vector<int>, int)':
towns.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = 0; i < values.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
towns.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i = 0; i < alive.size(); i += 2){
      |                  ~~^~~~~~~~~~~~~~
towns.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0; i < dead.size(); i++){
      |                 ~~^~~~~~~~~~~~~
towns.cpp:65:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |  return (alive[0].size() > n / 2) ? -1 : 1;
      |          ~~~~~~~~~~~~~~~~^~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:69:12: warning: conversion from 'time_t' {aka 'long int'} to 'unsigned int' may change value [-Wconversion]
   69 |  srand(time(0));
      |        ~~~~^~~
towns.cpp:106:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |  else if(lMid.size() > N / 2)
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:108:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |  else if(rMid.size() > N / 2)
      |          ~~~~~~~~~~~~^~~~~~~
#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...