제출 #60235

#제출 시각아이디문제언어결과실행 시간메모리
60235reality도시들 (IOI15_towns)C++17
25 / 100
29 ms876 KiB
#include "towns.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

const int N = 256;

int D[N][N];

int get(int x,int y) {
	if (D[x][y] != -1)
		return D[x][y];
	return D[x][y] = D[y][x] = getDistance(x,y);
}

int hubDistance(int n, int sub) {
	memset(D,-1,sizeof(D));
	int x = 0;
	for (int i = 0;i < n;++i)
		D[i][i] = 0;
	for (int i = 0;i < n;++i)
		if (get(0,i) > get(0,x))
			x = i;
	int y = x;
	for (int i = 0;i < n;++i)
		if (get(x,i) > get(x,y))
			y = i;
	vi s;
	map < int , int > M;
	for (int k = 0;k < n;++k)
		s.pb((get(x,y) - (get(x,k) - get(y,k))) / 2),++M[s.back()];
	sort(all(s));
	s.resize(unique(all(s)) - s.begin());
	int ans = 2e9;
	for (auto it : s)
		smin(ans,max(it,D[x][y] - it));
	if (sub <= 2)
		return ans;
	pair < int , pii > bst = mp(-1,mp(-1,-1));
	int ds = -1;
	for (auto dist : s)
		if (max(dist,D[x][y] - dist) == ans) {
			int a = 0,b = 0;
			for (auto it : M) {
				if (it.fi < dist)
					a += it.se;
				if (dist < it.fi)
					b += it.se;
			}
			if (a < b)
				swap(a,b);
			auto curr = mp(a + b,mp(a,b));
			if (bst > curr)
				bst = curr,ds = dist;
		}
	int dist = ds;
	int a = bst.se.fi;
	int b = bst.se.se;
	if (max(a,b) > (n / 2))
		return -ans;
	vi v;
	for (int k = 0;k < n;++k)
		if (get(x,y) - (get(x,k) - get(y,k)) == 2 * dist)
			v.pb(k);
	int sz = v.size();
	vi was(sz,1);
	int mx = max(a,b);
	for (int i = 0;i < sz;++i)
		if (was[i]) {
			int cnt = 1;
			for (int j = 0;j < sz;++j)
				if (was[j]) {
					if (get(y,v[i]) + get(y,v[j]) - get(v[i],v[j]) != 2 * dist)
						++cnt,was[j] = 0;
				}
			smax(mx,cnt);
		}
	if (mx <= (n / 2))
		return ans;
	return -ans;
}

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:77:17: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int sz = v.size();
           ~~~~~~^~
#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...