Submission #46239

# Submission time Handle Problem Language Result Execution time Memory
46239 2018-04-18T09:18:33 Z RayaBurong25_1 Towns (IOI15_towns) C++14
0 / 100
3 ms 1012 KB
#include "towns.h"
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <cassert>
int Dist[111][111];
int X[111];
int L[111] = {0}, Ln[111] = {0};
int M[111] = {0}, Mn[111] = {0};
int R[111] = {0}, Rn[111] = {0};
std::map<int, std::vector<std::pair<int, int> > > Map;
int calcMn(std::vector<std::pair<int, int> > V)
{
	int In[111] = {0};
	int Cnt, Max = 0;
	int i, j;
	for (i = 0; i < V.size(); i++)
	{
		if (!In[i])
		{
			Cnt = 1;
			In[i] = 1;
			for (j = 0; j < V.size(); j++)
			{
				if (!In[j] && getDistance(V[i].second, V[j].second) < V[i].first + V[j].first)
				{
					In[j] = 1;
					Cnt++;
				}
			}
			if (Cnt > Max)
				Max = Cnt;
		}
	}
	return Max;
}
int hubDistance(int N, int sub)
{
	int i, j;
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < N; j++)
		{
			if (i == j)
				Dist[i][j] = 0;
			else
				Dist[i][j] = -1;
		}
	}
	int u = 0;
	for (i = 0; i < N; i++)
	{
		if (Dist[0][i] == -1)
		{
			Dist[0][i] = getDistance(0, i);
			Dist[i][0] = Dist[0][i];
		}
		if (Dist[0][i] > Dist[0][u])
			u = i;
	}
	int v = u;
	for (i = 0; i < N; i++)
	{
		if (Dist[u][i] == -1)
		{
			Dist[u][i] = getDistance(u, i);
			Dist[i][u] = Dist[u][i];
		}
		if (Dist[u][i] > Dist[u][v])
			v = i;
	}
	for (i = 0; i < N; i++)
	{
		if (Dist[v][i] == -1)
		{
			Dist[v][i] = getDistance(v, i);
			Dist[i][v] = Dist[v][i];
		}
	}
	// printf("diameter %d-%d\n", u, v);
	int x, y;
	std::vector<std::pair<int, int> > emptyv(0);
	for (i = 0; i < N; i++)
	{
		y = (Dist[u][i] + Dist[i][v] - Dist[u][v])/2;
		x = Dist[u][i] - y;
		// assert(x >= 0 && y >= 0);
		// printf("i%d x%d y%d\n", i, x, y);
		if (Map.find(x) == Map.end())
		{
			Map.insert({x, emptyv});
		}
		Map[x].push_back({y, i});
	}
	int Ans = 1000000007, Hub = 0;
	std::map<int, std::vector<std::pair<int, int> > >::iterator it;
	for (it = Map.begin(), i = 0; it != Map.end(); it++, i++)
	{
		X[i] = it->first;
		Mn[i] = it->second.size();
		if (i > 0)
		{
			L[i] = std::max(L[i - 1], M[i - 1]) + (X[i] - X[i - 1]);
			Ln[i] = Ln[i - 1] + M[i - 1];
		}
		for (j = 0; j < it->second.size(); j++)
			M[i] = std::max(M[i], it->second[j].first);
	}
	int l = i;
	it--;
	for (i = l - 1; i >= 0; i--, it--)
	{
		assert(L[i] >= 0 && L[i] <= Dist[u][v]);
		assert(M[i] >= 0 && M[i] <= Dist[u][v]);
		assert(R[i] >= 0 && R[i] <= Dist[u][v]);
		if (i < l - 1)
		{
			R[i] = std::max(R[i + 1], M[i + 1]) + (X[i + 1] - X[i]);
			Rn[i] = Rn[i + 1] + M[i + 1];
		}
		// printf("L%d M%d R%d\n", L[i], M[i], R[i]);
		if (std::max(std::max(L[i], M[i]), R[i]) <= Ans)
		{
			Ans = std::max(std::max(L[i], M[i]), R[i]);
			if (sub == 3)
			{
				Hub |= std::max(std::max(Ln[i], calcMn(it->second)), Rn[i]) <= N/2;
			}
			else if (sub == 4)
			{
				Hub |= std::max(std::max(Ln[i], Mn[i]), Rn[i]) <= N/2;
			}
		}
	}
	// assert(Dist[u][v] != -1);
	// assert(Ans <= Dist[u][v]);
	if (Hub)
		return Ans;
	else
		return -Ans;
}

Compilation message

towns.cpp: In function 'int calcMn(std::vector<std::pair<int, int> >)':
towns.cpp:18:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < V.size(); i++)
              ~~^~~~~~~~~~
towns.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (j = 0; j < V.size(); j++)
                ~~^~~~~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:101:26: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
   Mn[i] = it->second.size();
           ~~~~~~~~~~~~~~~^~
towns.cpp:107:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (j = 0; j < it->second.size(); j++)
               ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 892 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 892 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -