Submission #990735

# Submission time Handle Problem Language Result Execution time Memory
990735 2024-05-31T06:55:49 Z starchan Towns (IOI15_towns) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "towns.h"
using namespace std;
#define in array<int, 2>
#define pb push_back
#define pob pop_back

int hubDistance(int n, int sub)
{
	in opt = {0, 0}
	for(int i = 1; i < n; i++)
		opt = max(opt, {getDistance(i, 0), i});
	int a = opt[1]; opt = {0, a};
	vector<int> d1(n), d2(n); d1[a] = 0;
	for(int i = 0; i < n; i++)
	{
		if(i == a) continue;
		opt = max(opt, {d1[i] = getDistance(i, a), i});
	}
	auto [D, b] = opt; d2[b] = 0;
	map<int, vector<int>> diam; diam[0].pb(a); diam[D].pb(b);
	for(int i = 0; i < n; i++)
	{
		if(i == a || i == b)
			continue;
		d2[i] = getDistance(i, b);
		diam[(d1[i]-d2[i]+D)/2].pb(i);
	}
	int R = 1e9+1;
	vector<vector<int>> vi;
	vector<int> dist;
	for(auto [X, v]: diam)
	{
		R = min(R, max(X, D-X));
		vi.pb(v); dist.pb(X); 
	}
	int N = vi.size();
	//0, 1, .., N-1
	//has information for stuff on diameter.
	int pre = 0;
	for(int i = 0; i < N-2; i++)
	{
		pre+=vi[i].size();
		if(R != max(dist[i+1], D-dist[i+1]))
			continue;
		if(2*pre > n)
			break;
		if(2*(n-pre-vi[i+1].size()) > n)
			continue;
		if(2*(vi[i+1].size()) <= n)
			return R;
		//Now we need to check if the i+1th thingie, (as we are accessing) is centroid or not.
		//This must be done in <= N/2 queries for AC. <= 2N queries is ok too, if we want good partial score.
		int g = vi[i+1][0]; int rt = d1[g]-dist[i+1]; int cnt = 0;
		for(auto x: vi[i+1])
		{
			if(x == g)
				continue;
			int q_rt = d1[x]-dist[i+1];
			if((rt+q_rt) == getDistance(x, g))
			{
				if(cnt)
					cnt--;
				else
				{
					cnt = 1; rt = q_rt;
					g = x;
				}
			}
			else
				cnt++;
		}
		int SP = 1;
		for(auto x: vi[i+1])
		{
			if(x == g)
				continue;
			int q_rt = d1[x]-dist[i+1];
			if((rt+q_rt) == getDistance(x, g))
				SP++;
		}
		if((2*SP) <= n)
			return R;
	}
	return -R;
}	

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:11:2: error: expected ',' or ';' before 'for'
   11 |  for(int i = 1; i < n; i++)
      |  ^~~
towns.cpp:11:17: error: 'i' was not declared in this scope
   11 |  for(int i = 1; i < n; i++)
      |                 ^
towns.cpp:12:40: error: expected primary-expression before ')' token
   12 |   opt = max(opt, {getDistance(i, 0), i});
      |                                        ^
towns.cpp:15:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
   15 |  for(int i = 0; i < n; i++)
      |          ^
towns.cpp:11:17: note: shadowed declaration is here
   11 |  for(int i = 1; i < n; i++)
      |                 ^
towns.cpp:22:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
   22 |  for(int i = 0; i < n; i++)
      |          ^
towns.cpp:11:17: note: shadowed declaration is here
   11 |  for(int i = 1; i < n; i++)
      |                 ^
towns.cpp:37:17: warning: conversion from 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   37 |  int N = vi.size();
      |          ~~~~~~~^~
towns.cpp:41:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
   41 |  for(int i = 0; i < N-2; i++)
      |          ^
towns.cpp:11:17: note: shadowed declaration is here
   11 |  for(int i = 1; i < n; i++)
      |                 ^
towns.cpp:43:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   43 |   pre+=vi[i].size();
      |                   ^
towns.cpp:48:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |   if(2*(n-pre-vi[i+1].size()) > n)
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
towns.cpp:50:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |   if(2*(vi[i+1].size()) <= n)
      |      ~~~~~~~~~~~~~~~~~~~^~~~
towns.cpp:8:28: warning: unused parameter 'sub' [-Wunused-parameter]
    8 | int hubDistance(int n, int sub)
      |                        ~~~~^~~